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"
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_NCMBUTTONDBLCLK
52 #define MAX_PACK_COUNT 4
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 filter */
310 inline static BOOL
check_message_filter( const MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
312 if (hwnd
&& msg
->hwnd
!= hwnd
&& !IsChild( hwnd
, msg
->hwnd
)) return FALSE
;
313 if (first
|| last
) return (msg
->message
>= first
&& msg
->message
<= last
);
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
:
372 char ch
= LOWORD(wparam
);
374 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
375 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
382 ch
[0] = (wparam
>> 8);
383 ch
[1] = (wparam
& 0xff);
384 if (ch
[0]) MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
385 else MultiByteToWideChar(CP_ACP
, 0, &ch
[1], 1, &wch
, 1);
386 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
394 /***********************************************************************
397 * Convert the wparam of a Unicode message to ASCII.
399 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
404 case EM_SETPASSWORDCHAR
:
411 WCHAR wch
= LOWORD(wparam
);
413 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
414 wparam
= MAKEWPARAM( ch
, HIWORD(wparam
) );
419 WCHAR wch
= LOWORD(wparam
);
422 if (WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, ch
, 2, NULL
, NULL
) == 2)
423 wparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wparam
) );
425 wparam
= MAKEWPARAM( ch
[0], HIWORD(wparam
) );
433 /***********************************************************************
436 * Pack a message for sending to another process.
437 * Return the size of the data we expect in the message reply.
438 * Set data->count to -1 if there is an error.
440 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
441 struct packed_message
*data
)
449 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
450 push_data( data
, cs
, sizeof(*cs
) );
451 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
452 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
456 case WM_ASKCBFORMATNAME
:
457 return wparam
* sizeof(WCHAR
);
458 case WM_WININICHANGE
:
459 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
462 case WM_DEVMODECHANGE
:
467 push_string( data
, (LPWSTR
)lparam
);
469 case WM_GETMINMAXINFO
:
470 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
471 return sizeof(MINMAXINFO
);
473 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
476 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
477 return sizeof(MEASUREITEMSTRUCT
);
479 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
482 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
484 case WM_WINDOWPOSCHANGING
:
485 case WM_WINDOWPOSCHANGED
:
486 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
487 return sizeof(WINDOWPOS
);
490 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
491 push_data( data
, cp
, sizeof(*cp
) );
492 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
496 /* WM_NOTIFY cannot be sent across processes (MSDN) */
500 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
502 case WM_STYLECHANGING
:
503 case WM_STYLECHANGED
:
504 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
509 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
514 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
515 push_data( data
, nc
, sizeof(*nc
) );
516 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
517 return sizeof(*nc
) + sizeof(*nc
->lppos
);
520 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
522 case SBM_SETSCROLLINFO
:
523 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
525 case SBM_GETSCROLLINFO
:
526 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
527 return sizeof(SCROLLINFO
);
528 case SBM_GETSCROLLBARINFO
:
530 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
531 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
532 push_data( data
, info
, size
);
540 if (wparam
) size
+= sizeof(DWORD
);
541 if (lparam
) size
+= sizeof(DWORD
);
546 case CB_GETDROPPEDCONTROLRECT
:
550 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
554 WORD
*pw
= (WORD
*)lparam
;
555 push_data( data
, pw
, sizeof(*pw
) );
556 return *pw
* sizeof(WCHAR
);
560 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
563 case CB_INSERTSTRING
:
565 case CB_FINDSTRINGEXACT
:
566 case CB_SELECTSTRING
:
567 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
570 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
571 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
573 case LB_INSERTSTRING
:
575 case LB_FINDSTRINGEXACT
:
576 case LB_SELECTSTRING
:
577 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
580 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
581 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
583 return wparam
* sizeof(UINT
);
585 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
586 return sizeof(MDINEXTMENU
);
589 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
593 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
594 push_data( data
, cs
, sizeof(*cs
) );
595 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
596 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
599 case WM_MDIGETACTIVE
:
600 if (lparam
) return sizeof(BOOL
);
602 case WM_WINE_SETWINDOWPOS
:
603 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
605 case WM_WINE_KEYBOARD_LL_HOOK
:
606 push_data( data
, (KBDLLHOOKSTRUCT
*)lparam
, sizeof(KBDLLHOOKSTRUCT
) );
608 case WM_WINE_MOUSE_LL_HOOK
:
609 push_data( data
, (MSLLHOOKSTRUCT
*)lparam
, sizeof(MSLLHOOKSTRUCT
) );
612 if (!wparam
) return 0;
615 /* these contain an HFONT */
618 /* these contain an HDC */
620 case WM_ICONERASEBKGND
:
622 case WM_CTLCOLORMSGBOX
:
623 case WM_CTLCOLOREDIT
:
624 case WM_CTLCOLORLISTBOX
:
627 case WM_CTLCOLORSCROLLBAR
:
628 case WM_CTLCOLORSTATIC
:
631 /* these contain an HGLOBAL */
632 case WM_PAINTCLIPBOARD
:
633 case WM_SIZECLIPBOARD
:
634 /* these contain HICON */
637 case WM_QUERYDRAGICON
:
638 case WM_QUERYPARKICON
:
639 /* these contain pointers */
641 case WM_QUERYDROPOBJECT
:
645 case WM_DEVICECHANGE
:
646 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
654 /***********************************************************************
657 * Unpack a message received from another process.
659 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
660 void **buffer
, size_t size
)
669 CREATESTRUCTW
*cs
= *buffer
;
670 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
671 if (size
< sizeof(*cs
)) return FALSE
;
673 if (HIWORD(cs
->lpszName
))
675 if (!check_string( str
, size
)) return FALSE
;
677 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
678 str
+= strlenW(str
) + 1;
680 if (HIWORD(cs
->lpszClass
))
682 if (!check_string( str
, size
)) return FALSE
;
688 case WM_ASKCBFORMATNAME
:
689 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
691 case WM_WININICHANGE
:
692 if (!*lparam
) return TRUE
;
695 case WM_DEVMODECHANGE
:
700 if (!check_string( *buffer
, size
)) return FALSE
;
702 case WM_GETMINMAXINFO
:
703 minsize
= sizeof(MINMAXINFO
);
706 minsize
= sizeof(DRAWITEMSTRUCT
);
709 minsize
= sizeof(MEASUREITEMSTRUCT
);
712 minsize
= sizeof(DELETEITEMSTRUCT
);
715 minsize
= sizeof(COMPAREITEMSTRUCT
);
717 case WM_WINDOWPOSCHANGING
:
718 case WM_WINDOWPOSCHANGED
:
719 case WM_WINE_SETWINDOWPOS
:
720 minsize
= sizeof(WINDOWPOS
);
724 COPYDATASTRUCT
*cp
= *buffer
;
725 if (size
< sizeof(*cp
)) return FALSE
;
728 minsize
= sizeof(*cp
) + cp
->cbData
;
734 /* WM_NOTIFY cannot be sent across processes (MSDN) */
737 minsize
= sizeof(HELPINFO
);
739 case WM_STYLECHANGING
:
740 case WM_STYLECHANGED
:
741 minsize
= sizeof(STYLESTRUCT
);
744 if (!*wparam
) minsize
= sizeof(RECT
);
747 NCCALCSIZE_PARAMS
*nc
= *buffer
;
748 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
749 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
753 if (!*lparam
) return TRUE
;
754 minsize
= sizeof(MSG
);
756 case SBM_SETSCROLLINFO
:
757 minsize
= sizeof(SCROLLINFO
);
759 case SBM_GETSCROLLINFO
:
760 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
762 case SBM_GETSCROLLBARINFO
:
763 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
768 if (*wparam
|| *lparam
)
770 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
771 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
772 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
777 case CB_GETDROPPEDCONTROLRECT
:
778 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
782 minsize
= sizeof(RECT
);
787 if (size
< sizeof(WORD
)) return FALSE
;
788 len
= *(WORD
*)*buffer
;
789 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
790 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
795 if (!*wparam
) return TRUE
;
796 minsize
= *wparam
* sizeof(UINT
);
799 case CB_INSERTSTRING
:
801 case CB_FINDSTRINGEXACT
:
802 case CB_SELECTSTRING
:
804 case LB_INSERTSTRING
:
806 case LB_FINDSTRINGEXACT
:
807 case LB_SELECTSTRING
:
808 if (!*buffer
) return TRUE
;
809 if (!check_string( *buffer
, size
)) return FALSE
;
813 size
= sizeof(ULONG_PTR
);
814 if (combobox_has_strings( hwnd
))
815 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
816 if (!get_buffer_space( buffer
, size
)) return FALSE
;
821 size
= sizeof(ULONG_PTR
);
822 if (listbox_has_strings( hwnd
))
823 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
824 if (!get_buffer_space( buffer
, size
)) return FALSE
;
828 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
831 minsize
= sizeof(MDINEXTMENU
);
832 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
836 minsize
= sizeof(RECT
);
837 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
841 MDICREATESTRUCTW
*cs
= *buffer
;
842 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
843 if (size
< sizeof(*cs
)) return FALSE
;
845 if (HIWORD(cs
->szTitle
))
847 if (!check_string( str
, size
)) return FALSE
;
849 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
850 str
+= strlenW(str
) + 1;
852 if (HIWORD(cs
->szClass
))
854 if (!check_string( str
, size
)) return FALSE
;
859 case WM_MDIGETACTIVE
:
860 if (!*lparam
) return TRUE
;
861 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
863 case WM_WINE_KEYBOARD_LL_HOOK
:
864 minsize
= sizeof(KBDLLHOOKSTRUCT
);
866 case WM_WINE_MOUSE_LL_HOOK
:
867 minsize
= sizeof(MSLLHOOKSTRUCT
);
870 if (!*wparam
) return TRUE
;
873 /* these contain an HFONT */
876 /* these contain an HDC */
878 case WM_ICONERASEBKGND
:
880 case WM_CTLCOLORMSGBOX
:
881 case WM_CTLCOLOREDIT
:
882 case WM_CTLCOLORLISTBOX
:
885 case WM_CTLCOLORSCROLLBAR
:
886 case WM_CTLCOLORSTATIC
:
889 /* these contain an HGLOBAL */
890 case WM_PAINTCLIPBOARD
:
891 case WM_SIZECLIPBOARD
:
892 /* these contain HICON */
895 case WM_QUERYDRAGICON
:
896 case WM_QUERYPARKICON
:
897 /* these contain pointers */
899 case WM_QUERYDROPOBJECT
:
903 case WM_DEVICECHANGE
:
904 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
908 return TRUE
; /* message doesn't need any unpacking */
911 /* default exit for most messages: check minsize and store buffer in lparam */
912 if (size
< minsize
) return FALSE
;
913 *lparam
= (LPARAM
)*buffer
;
918 /***********************************************************************
921 * Pack a reply to a message for sending to another process.
923 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
924 LRESULT res
, struct packed_message
*data
)
931 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
936 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
938 case WM_GETMINMAXINFO
:
939 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
942 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
944 case WM_WINDOWPOSCHANGING
:
945 case WM_WINDOWPOSCHANGED
:
946 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
949 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
951 case SBM_GETSCROLLINFO
:
952 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
956 case CB_GETDROPPEDCONTROLRECT
:
959 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
963 WORD
*ptr
= (WORD
*)lparam
;
964 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
968 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
970 case WM_MDIGETACTIVE
:
971 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
975 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
978 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
979 push_data( data
, nc
, sizeof(*nc
) );
980 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
986 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
987 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
990 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
993 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
995 case WM_ASKCBFORMATNAME
:
996 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1002 /***********************************************************************
1005 * Unpack a message reply received from another process.
1007 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1008 void *buffer
, size_t size
)
1015 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1016 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
1017 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1018 cs
->lpszName
= name
; /* restore the original pointers */
1019 cs
->lpszClass
= class;
1023 case WM_ASKCBFORMATNAME
:
1024 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1026 case WM_GETMINMAXINFO
:
1027 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1029 case WM_MEASUREITEM
:
1030 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
1032 case WM_WINDOWPOSCHANGING
:
1033 case WM_WINDOWPOSCHANGED
:
1034 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
1037 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
1039 case SBM_GETSCROLLINFO
:
1040 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1042 case SBM_GETSCROLLBARINFO
:
1043 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1046 case CB_GETDROPPEDCONTROLRECT
:
1047 case LB_GETITEMRECT
:
1050 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1053 size
= min( size
, (size_t)*(WORD
*)lparam
);
1054 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1056 case LB_GETSELITEMS
:
1057 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1061 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1064 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1066 case WM_MDIGETACTIVE
:
1067 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1071 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1074 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1075 WINDOWPOS
*wp
= nc
->lppos
;
1076 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1077 if (size
> sizeof(*nc
))
1079 size
-= sizeof(*nc
);
1080 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1082 nc
->lppos
= wp
; /* restore the original pointer */
1090 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1091 if (size
<= sizeof(DWORD
)) break;
1092 size
-= sizeof(DWORD
);
1093 buffer
= (DWORD
*)buffer
+ 1;
1095 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1099 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1100 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1101 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1102 cs
->szTitle
= title
; /* restore the original pointers */
1103 cs
->szClass
= class;
1107 ERR( "should not happen: unexpected message %x\n", message
);
1113 /***********************************************************************
1116 * Send a reply to a sent message.
1118 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1120 struct packed_message data
;
1121 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1123 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1124 if (!remove
&& replied
) return; /* replied already */
1127 info
->flags
|= ISMEX_REPLIED
;
1129 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1131 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1132 info
->msg
.lParam
, result
, &data
);
1135 SERVER_START_REQ( reply_message
)
1137 req
->type
= info
->type
;
1138 req
->result
= result
;
1139 req
->remove
= remove
;
1140 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1141 wine_server_call( req
);
1147 /***********************************************************************
1148 * handle_internal_message
1150 * Handle an internal Wine message instead of calling the window proc.
1152 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1154 if (hwnd
== GetDesktopWindow()) return 0;
1157 case WM_WINE_DESTROYWINDOW
:
1158 return WIN_DestroyWindow( hwnd
);
1159 case WM_WINE_SETWINDOWPOS
:
1160 if (USER_Driver
.pSetWindowPos
)
1161 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
)
1180 if (!USER_Driver
.pWindowMessage
) return 0;
1181 return USER_Driver
.pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1183 FIXME( "unknown internal message %x\n", msg
);
1188 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1189 * to the memory handle, we keep track (in the server side) of all pairs of handle
1190 * used (the client passes its value and the content of the memory handle), and
1191 * the server stored both values (the client, and the local one, created after the
1192 * content). When a ACK message is generated, the list of pair is searched for a
1193 * matching pair, so that the client memory handle can be returned.
1196 HGLOBAL client_hMem
;
1197 HGLOBAL server_hMem
;
1200 static struct DDE_pair
* dde_pairs
;
1201 static int dde_num_alloc
;
1202 static int dde_num_used
;
1204 static CRITICAL_SECTION dde_crst
;
1205 static CRITICAL_SECTION_DEBUG critsect_debug
=
1208 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1209 0, 0, { 0, (DWORD
)(__FILE__
": dde_crst") }
1211 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1213 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1218 EnterCriticalSection(&dde_crst
);
1220 /* now remember the pair of hMem on both sides */
1221 if (dde_num_used
== dde_num_alloc
)
1223 struct DDE_pair
* tmp
;
1225 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1226 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1228 tmp
= HeapAlloc( GetProcessHeap(), 0,
1229 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1233 LeaveCriticalSection(&dde_crst
);
1237 /* zero out newly allocated part */
1238 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1239 dde_num_alloc
+= GROWBY
;
1242 for (i
= 0; i
< dde_num_alloc
; i
++)
1244 if (dde_pairs
[i
].server_hMem
== 0)
1246 dde_pairs
[i
].client_hMem
= chm
;
1247 dde_pairs
[i
].server_hMem
= shm
;
1252 LeaveCriticalSection(&dde_crst
);
1256 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1261 EnterCriticalSection(&dde_crst
);
1262 for (i
= 0; i
< dde_num_alloc
; i
++)
1264 if (dde_pairs
[i
].server_hMem
== shm
)
1266 /* free this pair */
1267 dde_pairs
[i
].server_hMem
= 0;
1269 ret
= dde_pairs
[i
].client_hMem
;
1273 LeaveCriticalSection(&dde_crst
);
1277 /***********************************************************************
1280 * Post a DDE message
1282 static BOOL
post_dde_message( DWORD dest_tid
, struct packed_message
*data
, const struct send_message_info
*info
)
1288 HGLOBAL hunlock
= 0;
1292 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1298 /* DDE messages which don't require packing are:
1307 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1308 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1311 /* send back the value of h on the other side */
1312 push_data( data
, &h
, sizeof(HGLOBAL
) );
1314 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo
, uiHi
, (DWORD
)h
);
1319 /* uiHi should contain either an atom or 0 */
1320 TRACE( "send dde-ack %x atom=%x\n", uiLo
, uiHi
);
1321 lp
= MAKELONG( uiLo
, uiHi
);
1330 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1331 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1332 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1333 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1337 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1342 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1344 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1345 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1346 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1347 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1348 push_data( data
, ptr
, size
);
1349 hunlock
= (HGLOBAL
)uiLo
;
1352 TRACE( "send ddepack %u %x\n", size
, uiHi
);
1354 case WM_DDE_EXECUTE
:
1357 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1359 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1360 /* so that the other side can send it back on ACK */
1362 hunlock
= (HGLOBAL
)info
->lparam
;
1367 SERVER_START_REQ( send_message
)
1370 req
->type
= info
->type
;
1372 req
->win
= info
->hwnd
;
1373 req
->msg
= info
->msg
;
1374 req
->wparam
= info
->wparam
;
1376 req
->time
= GetCurrentTime();
1378 for (i
= 0; i
< data
->count
; i
++)
1379 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1380 if ((res
= wine_server_call( req
)))
1382 if (res
== STATUS_INVALID_PARAMETER
)
1383 /* FIXME: find a STATUS_ value for this one */
1384 SetLastError( ERROR_INVALID_THREAD_ID
);
1386 SetLastError( RtlNtStatusToDosError(res
) );
1389 FreeDDElParam(info
->msg
, info
->lparam
);
1392 if (hunlock
) GlobalUnlock(hunlock
);
1397 /***********************************************************************
1398 * unpack_dde_message
1400 * Unpack a posted DDE message received from another process.
1402 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1403 void **buffer
, size_t size
)
1414 /* hMem is being passed */
1415 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1416 if (!buffer
|| !*buffer
) return FALSE
;
1418 memcpy( &hMem
, *buffer
, size
);
1420 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1424 uiLo
= LOWORD( *lparam
);
1425 uiHi
= HIWORD( *lparam
);
1426 TRACE("recv dde-ack %x atom=%x\n", uiLo
, uiHi
);
1428 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1433 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1435 TRACE( "recv ddepack %u %x\n", size
, uiHi
);
1438 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
);
1439 if (hMem
&& (ptr
= GlobalLock( hMem
)))
1441 memcpy( ptr
, *buffer
, size
);
1442 GlobalUnlock( hMem
);
1448 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1450 case WM_DDE_EXECUTE
:
1453 if (!buffer
|| !*buffer
) return FALSE
;
1454 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
);
1455 if (hMem
&& (ptr
= GlobalLock( hMem
)))
1457 memcpy( ptr
, *buffer
, size
);
1458 GlobalUnlock( hMem
);
1459 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam
, (DWORD
)hMem
);
1460 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1466 } else return FALSE
;
1467 *lparam
= (LPARAM
)hMem
;
1473 /***********************************************************************
1476 * Call a window procedure and the corresponding hooks.
1478 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1479 BOOL unicode
, BOOL same_thread
)
1484 CWPRETSTRUCT cwpret
;
1485 MESSAGEQUEUE
*queue
= QUEUE_Current();
1487 if (queue
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1488 queue
->recursion_count
++;
1490 if (msg
& 0x80000000)
1492 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1496 /* first the WH_CALLWNDPROC hook */
1497 hwnd
= WIN_GetFullHandle( hwnd
);
1498 cwp
.lParam
= lparam
;
1499 cwp
.wParam
= wparam
;
1502 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1504 /* now call the window procedure */
1507 if (!(winproc
= (WNDPROC
)GetWindowLongPtrW( hwnd
, GWLP_WNDPROC
))) goto done
;
1508 result
= CallWindowProcW( winproc
, hwnd
, msg
, wparam
, lparam
);
1512 if (!(winproc
= (WNDPROC
)GetWindowLongPtrA( hwnd
, GWLP_WNDPROC
))) goto done
;
1513 result
= CallWindowProcA( winproc
, hwnd
, msg
, wparam
, lparam
);
1516 /* and finally the WH_CALLWNDPROCRET hook */
1517 cwpret
.lResult
= result
;
1518 cwpret
.lParam
= lparam
;
1519 cwpret
.wParam
= wparam
;
1520 cwpret
.message
= msg
;
1522 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1524 queue
->recursion_count
--;
1529 /***********************************************************************
1530 * send_parent_notify
1532 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1533 * the window has the WS_EX_NOPARENTNOTIFY style.
1535 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
1537 /* pt has to be in the client coordinates of the parent window */
1538 MapWindowPoints( 0, hwnd
, &pt
, 1 );
1543 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
1544 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
1545 if (!(parent
= GetParent(hwnd
))) break;
1546 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
1548 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
1549 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
1554 /***********************************************************************
1555 * process_raw_keyboard_message
1557 * returns TRUE if the contents of 'msg' should be passed to the application
1559 static BOOL
process_raw_keyboard_message( MSG
*msg
, HWND hwnd_filter
, UINT first
, UINT last
)
1563 event
.message
= msg
->message
;
1564 event
.hwnd
= msg
->hwnd
;
1565 event
.time
= msg
->time
;
1566 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
1567 event
.paramH
= msg
->lParam
& 0x7FFF;
1568 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
1569 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1570 return check_message_filter( msg
, hwnd_filter
, first
, last
);
1574 /***********************************************************************
1575 * process_cooked_keyboard_message
1577 * returns TRUE if the contents of 'msg' should be passed to the application
1579 static BOOL
process_cooked_keyboard_message( MSG
*msg
, BOOL remove
)
1583 /* Handle F1 key by sending out WM_HELP message */
1584 if ((msg
->message
== WM_KEYUP
) &&
1585 (msg
->wParam
== VK_F1
) &&
1586 (msg
->hwnd
!= GetDesktopWindow()) &&
1587 !MENU_IsMenuActive())
1590 hi
.cbSize
= sizeof(HELPINFO
);
1591 hi
.iContextType
= HELPINFO_WINDOW
;
1592 hi
.iCtrlId
= GetWindowLongPtrA( msg
->hwnd
, GWLP_ID
);
1593 hi
.hItemHandle
= msg
->hwnd
;
1594 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
1595 hi
.MousePos
= msg
->pt
;
1596 SendMessageW( msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
1600 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
1601 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
1603 /* skip this message */
1604 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
1611 /***********************************************************************
1612 * process_raw_mouse_message
1614 static BOOL
process_raw_mouse_message( MSG
*msg
, HWND hwnd_filter
, UINT first
,
1615 UINT last
, BOOL remove
)
1624 HWND hWndScope
= msg
->hwnd
;
1626 /* find the window to dispatch this mouse message to */
1629 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
1630 if (!(msg
->hwnd
= info
.hwndCapture
))
1632 /* If no capture HWND, find window which contains the mouse position.
1633 * Also find the position of the cursor hot spot (hittest) */
1634 if (!IsWindow(hWndScope
)) hWndScope
= 0;
1635 if (!(msg
->hwnd
= WINPOS_WindowFromPoint( hWndScope
, msg
->pt
, &hittest
)))
1636 msg
->hwnd
= GetDesktopWindow();
1639 event
.message
= msg
->message
;
1640 event
.time
= msg
->time
;
1641 event
.hwnd
= msg
->hwnd
;
1642 event
.paramL
= msg
->pt
.x
;
1643 event
.paramH
= msg
->pt
.y
;
1644 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1648 if (msg
->hwnd
!= hwnd_filter
&& !IsChild( hwnd_filter
, msg
->hwnd
)) return FALSE
;
1652 message
= msg
->message
;
1653 /* Note: windows has no concept of a non-client wheel message */
1654 if (message
!= WM_MOUSEWHEEL
)
1656 if (hittest
!= HTCLIENT
)
1658 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
1659 msg
->wParam
= hittest
;
1663 /* coordinates don't get translated while tracking a menu */
1664 /* FIXME: should differentiate popups and top-level menus */
1665 if (!(info
.flags
& GUI_INMENUMODE
))
1666 ScreenToClient( msg
->hwnd
, &pt
);
1669 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
1671 /* translate double clicks */
1673 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1674 (msg
->message
== WM_RBUTTONDOWN
) ||
1675 (msg
->message
== WM_MBUTTONDOWN
))
1677 /* translate double clicks -
1678 * note that ...MOUSEMOVEs can slip in between
1679 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1681 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
1682 hittest
!= HTCLIENT
||
1683 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
1685 if ((msg
->message
== clk_msg
.message
) &&
1686 (msg
->hwnd
== clk_msg
.hwnd
) &&
1687 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
1688 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
1689 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
1691 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1692 msg
->message
= 0; /* to clear the double click conditions */
1697 if (message
< first
|| message
> last
) remove
= FALSE
;
1699 /* update static double click conditions */
1700 if (remove
) clk_msg
= *msg
;
1703 msg
->message
= message
;
1704 if (first
|| last
) return (message
>= first
&& message
<= last
);
1709 /***********************************************************************
1710 * process_cooked_mouse_message
1712 * returns TRUE if the contents of 'msg' should be passed to the application
1714 static BOOL
process_cooked_mouse_message( MSG
*msg
, ULONG_PTR extra_info
, BOOL remove
)
1716 MOUSEHOOKSTRUCT hook
;
1717 INT hittest
= HTCLIENT
;
1718 UINT raw_message
= msg
->message
;
1721 if (msg
->message
>= WM_NCMOUSEFIRST
&& msg
->message
<= WM_NCMOUSELAST
)
1723 raw_message
+= WM_MOUSEFIRST
- WM_NCMOUSEFIRST
;
1724 hittest
= msg
->wParam
;
1726 if (raw_message
== WM_LBUTTONDBLCLK
||
1727 raw_message
== WM_RBUTTONDBLCLK
||
1728 raw_message
== WM_MBUTTONDBLCLK
)
1730 raw_message
+= WM_LBUTTONDOWN
- WM_LBUTTONDBLCLK
;
1734 hook
.hwnd
= msg
->hwnd
;
1735 hook
.wHitTestCode
= hittest
;
1736 hook
.dwExtraInfo
= extra_info
;
1737 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
1738 msg
->message
, (LPARAM
)&hook
, TRUE
))
1741 hook
.hwnd
= msg
->hwnd
;
1742 hook
.wHitTestCode
= hittest
;
1743 hook
.dwExtraInfo
= extra_info
;
1744 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, msg
->message
, (LPARAM
)&hook
, TRUE
);
1748 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
1750 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
1751 MAKELONG( hittest
, raw_message
));
1755 if (!remove
|| GetCapture()) return TRUE
;
1759 if ((raw_message
== WM_LBUTTONDOWN
) ||
1760 (raw_message
== WM_RBUTTONDOWN
) ||
1761 (raw_message
== WM_MBUTTONDOWN
))
1763 /* Send the WM_PARENTNOTIFY,
1764 * note that even for double/nonclient clicks
1765 * notification message is still WM_L/M/RBUTTONDOWN.
1767 send_parent_notify( msg
->hwnd
, raw_message
, 0, msg
->pt
);
1769 /* Activate the window if needed */
1771 if (msg
->hwnd
!= GetActiveWindow())
1773 HWND hwndTop
= msg
->hwnd
;
1776 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
1777 hwndTop
= GetParent( hwndTop
);
1780 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
1782 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
1783 MAKELONG( hittest
, raw_message
) );
1786 case MA_NOACTIVATEANDEAT
:
1791 case MA_ACTIVATEANDEAT
:
1796 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
1799 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret
);
1806 /* send the WM_SETCURSOR message */
1808 /* Windows sends the normal mouse message as the message parameter
1809 in the WM_SETCURSOR message even if it's non-client mouse message */
1810 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
1811 MAKELONG( hittest
, raw_message
));
1817 /***********************************************************************
1818 * process_hardware_message
1820 * Process a hardware message; return TRUE if message should be passed on to the app
1822 static BOOL
process_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, HWND hwnd
,
1823 UINT first
, UINT last
, BOOL remove
)
1827 if (is_keyboard_message( msg
->message
))
1829 if (!process_raw_keyboard_message( msg
, hwnd
, first
, last
)) return FALSE
;
1830 ret
= process_cooked_keyboard_message( msg
, remove
);
1832 else if (is_mouse_message( msg
->message
))
1834 if (!process_raw_mouse_message( msg
, hwnd
, first
, last
, remove
)) return FALSE
;
1835 ret
= process_cooked_mouse_message( msg
, extra_info
, remove
);
1839 ERR( "unknown message type %x\n", msg
->message
);
1843 /* tell the server we have passed it to the app
1844 * (even though we may end up dropping it later on)
1846 SERVER_START_REQ( reply_message
)
1848 req
->type
= MSG_HARDWARE
;
1850 req
->remove
= remove
|| !ret
;
1851 if (wine_server_call( req
))
1852 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1859 /***********************************************************************
1860 * call_sendmsg_callback
1862 * Call the callback function of SendMessageCallback.
1864 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1865 ULONG_PTR data
, LRESULT result
)
1867 if (TRACE_ON(relay
))
1868 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1869 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1871 callback( hwnd
, msg
, data
, result
);
1872 if (TRACE_ON(relay
))
1873 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1874 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1879 /***********************************************************************
1882 * Retrieve the hook procedure real value for a module-relative proc
1884 static void *get_hook_proc( void *proc
, const WCHAR
*module
)
1888 if (!(mod
= GetModuleHandleW(module
)))
1890 TRACE( "loading %s\n", debugstr_w(module
) );
1891 /* FIXME: the library will never be freed */
1892 if (!(mod
= LoadLibraryW(module
))) return NULL
;
1894 return (char *)mod
+ (ULONG_PTR
)proc
;
1898 /***********************************************************************
1901 * Peek for a message matching the given parameters. Return FALSE if none available.
1902 * All pending sent messages are processed before returning.
1904 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1907 ULONG_PTR extra_info
= 0;
1908 MESSAGEQUEUE
*queue
= QUEUE_Current();
1909 struct received_message_info info
, *old_info
;
1910 int get_next_hw
= 0; /* set when the previous message was a rejected hardware message */
1912 if (!first
&& !last
) last
= ~0;
1917 void *buffer
= NULL
;
1918 size_t size
= 0, buffer_size
= 0;
1920 do /* loop while buffer is too small */
1922 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1924 SERVER_START_REQ( get_message
)
1927 req
->get_win
= hwnd
;
1928 req
->get_first
= first
;
1929 req
->get_last
= last
;
1930 req
->get_next_hw
= get_next_hw
;
1931 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
1932 if (!(res
= wine_server_call( req
)))
1934 size
= wine_server_reply_size( reply
);
1935 info
.type
= reply
->type
;
1936 info
.msg
.hwnd
= reply
->win
;
1937 info
.msg
.message
= reply
->msg
;
1938 info
.msg
.wParam
= reply
->wparam
;
1939 info
.msg
.lParam
= reply
->lparam
;
1940 info
.msg
.time
= reply
->time
;
1941 info
.msg
.pt
.x
= reply
->x
;
1942 info
.msg
.pt
.y
= reply
->y
;
1943 info
.hook
= reply
->hook
;
1944 info
.hook_proc
= reply
->hook_proc
;
1945 extra_info
= reply
->info
;
1949 HeapFree( GetProcessHeap(), 0, buffer
);
1950 buffer_size
= reply
->total
;
1954 } while (res
== STATUS_BUFFER_OVERFLOW
);
1956 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
);
2023 if (!process_hardware_message( &info
.msg
, extra_info
,
2024 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
2026 TRACE("dropping msg %x\n", info
.msg
.message
);
2027 goto next
; /* ignore it */
2029 queue
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2032 queue
->GetMessageExtraInfoVal
= extra_info
;
2033 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2035 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2036 &info
.msg
.lParam
, &buffer
, size
))
2038 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2039 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2040 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
, size
);
2041 goto next
; /* ignore it */
2045 HeapFree( GetProcessHeap(), 0, buffer
);
2049 /* if we get here, we have a sent message; call the window procedure */
2050 old_info
= queue
->receive_info
;
2051 queue
->receive_info
= &info
;
2052 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2053 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
);
2054 reply_message( &info
, result
, TRUE
);
2055 queue
->receive_info
= old_info
;
2057 HeapFree( GetProcessHeap(), 0, buffer
);
2062 /***********************************************************************
2063 * process_sent_messages
2065 * Process all pending sent messages.
2067 inline static void process_sent_messages(void)
2070 peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
2074 /***********************************************************************
2075 * wait_message_reply
2077 * Wait until a sent message gets replied to.
2079 static void wait_message_reply( UINT flags
)
2081 MESSAGEQUEUE
*queue
;
2083 if (!(queue
= QUEUE_Current())) return;
2087 unsigned int wake_bits
= 0, changed_bits
= 0;
2090 SERVER_START_REQ( set_queue_mask
)
2092 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2093 req
->changed_mask
= req
->wake_mask
;
2095 if (!wine_server_call( req
))
2097 wake_bits
= reply
->wake_bits
;
2098 changed_bits
= reply
->changed_bits
;
2103 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2104 if (wake_bits
& QS_SENDMESSAGE
)
2106 /* Process the sent message immediately */
2107 process_sent_messages();
2111 /* now wait for it */
2113 ReleaseThunkLock( &dwlc
);
2115 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
2116 res
= USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &queue
->server_queue
,
2117 INFINITE
, QS_ALLINPUT
, 0 );
2119 res
= WaitForSingleObject( queue
->server_queue
, INFINITE
);
2121 if (dwlc
) RestoreThunkLock( dwlc
);
2125 /***********************************************************************
2126 * put_message_in_queue
2128 * Put a sent message into the destination queue.
2129 * For inter-process message, reply_size is set to expected size of reply data.
2131 static BOOL
put_message_in_queue( DWORD dest_tid
, const struct send_message_info
*info
,
2132 size_t *reply_size
)
2134 struct packed_message data
;
2136 int i
, timeout
= -1;
2138 if (info
->type
!= MSG_NOTIFY
&&
2139 info
->type
!= MSG_CALLBACK
&&
2140 info
->type
!= MSG_POSTED
&&
2141 info
->timeout
!= INFINITE
)
2142 timeout
= info
->timeout
;
2145 if (info
->type
== MSG_OTHER_PROCESS
)
2147 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2148 if (data
.count
== -1)
2150 WARN( "cannot pack message %x\n", info
->msg
);
2154 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
2156 return post_dde_message( dest_tid
, &data
, info
);
2159 SERVER_START_REQ( send_message
)
2162 req
->type
= info
->type
;
2164 req
->win
= info
->hwnd
;
2165 req
->msg
= info
->msg
;
2166 req
->wparam
= info
->wparam
;
2167 req
->lparam
= info
->lparam
;
2168 req
->time
= GetCurrentTime();
2169 req
->timeout
= timeout
;
2171 if (info
->type
== MSG_CALLBACK
)
2173 req
->callback
= info
->callback
;
2174 req
->info
= info
->data
;
2177 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
2178 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
2179 if ((res
= wine_server_call( req
)))
2181 if (res
== STATUS_INVALID_PARAMETER
)
2182 /* FIXME: find a STATUS_ value for this one */
2183 SetLastError( ERROR_INVALID_THREAD_ID
);
2185 SetLastError( RtlNtStatusToDosError(res
) );
2193 /***********************************************************************
2196 * Retrieve a message reply from the server.
2198 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
2199 size_t reply_size
, LRESULT
*result
)
2202 void *reply_data
= NULL
;
2206 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
2208 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size
);
2212 SERVER_START_REQ( get_message_reply
)
2215 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
2216 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
2217 reply_size
= wine_server_reply_size( reply
);
2220 if (!status
&& reply_size
)
2221 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
2223 HeapFree( GetProcessHeap(), 0, reply_data
);
2225 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
2226 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
2227 info
->lparam
, *result
, status
);
2229 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2230 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
2235 /***********************************************************************
2236 * send_inter_thread_message
2238 static LRESULT
send_inter_thread_message( DWORD dest_tid
, const struct send_message_info
*info
,
2243 size_t reply_size
= 0;
2245 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2246 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
2248 if (!put_message_in_queue( dest_tid
, info
, &reply_size
)) return 0;
2250 /* there's no reply to wait for on notify/callback messages */
2251 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
2253 locks
= WIN_SuspendWndsLock();
2255 wait_message_reply( info
->flags
);
2256 ret
= retrieve_reply( info
, reply_size
, res_ptr
);
2258 WIN_RestoreWndsLock( locks
);
2263 /***********************************************************************
2264 * MSG_SendInternalMessageTimeout
2266 * Same as SendMessageTimeoutW but sends the message to a specific thread
2267 * without requiring a window handle. Only works for internal Wine messages.
2269 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
2270 UINT msg
, WPARAM wparam
, LPARAM lparam
,
2271 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2273 struct send_message_info info
;
2274 LRESULT ret
, result
;
2276 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
2278 info
.type
= MSG_UNICODE
;
2281 info
.wparam
= wparam
;
2282 info
.lparam
= lparam
;
2284 info
.timeout
= timeout
;
2286 if (USER_IsExitingThread( dest_tid
)) return 0;
2288 if (dest_tid
== GetCurrentThreadId())
2290 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
2295 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2296 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2298 if (ret
&& res_ptr
) *res_ptr
= result
;
2303 /***********************************************************************
2304 * SendMessageTimeoutW (USER32.@)
2306 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2307 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2309 struct send_message_info info
;
2310 DWORD dest_tid
, dest_pid
;
2311 LRESULT ret
, result
;
2313 info
.type
= MSG_UNICODE
;
2316 info
.wparam
= wparam
;
2317 info
.lparam
= lparam
;
2319 info
.timeout
= timeout
;
2321 if (is_broadcast(hwnd
))
2323 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2324 if (res_ptr
) *res_ptr
= 1;
2328 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2330 if (USER_IsExitingThread( dest_tid
)) return 0;
2332 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2334 if (dest_tid
== GetCurrentThreadId())
2336 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2341 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2342 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2345 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2346 if (ret
&& res_ptr
) *res_ptr
= result
;
2351 /***********************************************************************
2352 * SendMessageTimeoutA (USER32.@)
2354 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2355 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2357 struct send_message_info info
;
2358 DWORD dest_tid
, dest_pid
;
2359 LRESULT ret
, result
;
2361 info
.type
= MSG_ASCII
;
2364 info
.wparam
= wparam
;
2365 info
.lparam
= lparam
;
2367 info
.timeout
= timeout
;
2369 if (is_broadcast(hwnd
))
2371 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2372 if (res_ptr
) *res_ptr
= 1;
2376 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2378 if (USER_IsExitingThread( dest_tid
)) return 0;
2380 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2382 if (dest_tid
== GetCurrentThreadId())
2384 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, FALSE
, TRUE
);
2387 else if (dest_pid
== GetCurrentProcessId())
2389 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2393 /* inter-process message: need to map to Unicode */
2394 info
.type
= MSG_OTHER_PROCESS
;
2395 if (is_unicode_message( info
.msg
))
2397 if (WINPROC_MapMsg32ATo32W( info
.hwnd
, info
.msg
, &info
.wparam
, &info
.lparam
) == -1)
2399 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2400 result
= WINPROC_UnmapMsg32ATo32W( info
.hwnd
, info
.msg
, info
.wparam
,
2401 info
.lparam
, result
);
2403 else ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2405 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2406 if (ret
&& res_ptr
) *res_ptr
= result
;
2411 /***********************************************************************
2412 * SendMessageW (USER32.@)
2414 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2417 SendMessageTimeoutW( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, INFINITE
, &res
);
2422 /***********************************************************************
2423 * SendMessageA (USER32.@)
2425 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2428 SendMessageTimeoutA( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, INFINITE
, &res
);
2433 /***********************************************************************
2434 * SendNotifyMessageA (USER32.@)
2436 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2438 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2442 /***********************************************************************
2443 * SendNotifyMessageW (USER32.@)
2445 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2447 struct send_message_info info
;
2451 if (is_pointer_message(msg
))
2453 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2457 info
.type
= MSG_NOTIFY
;
2460 info
.wparam
= wparam
;
2461 info
.lparam
= lparam
;
2464 if (is_broadcast(hwnd
))
2466 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2470 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2472 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2474 if (dest_tid
== GetCurrentThreadId())
2476 call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2479 return send_inter_thread_message( dest_tid
, &info
, &result
);
2483 /***********************************************************************
2484 * SendMessageCallbackA (USER32.@)
2486 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2487 SENDASYNCPROC callback
, ULONG_PTR data
)
2489 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
),
2490 lparam
, callback
, data
);
2494 /***********************************************************************
2495 * SendMessageCallbackW (USER32.@)
2497 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2498 SENDASYNCPROC callback
, ULONG_PTR data
)
2500 struct send_message_info info
;
2504 if (is_pointer_message(msg
))
2506 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2510 info
.type
= MSG_CALLBACK
;
2513 info
.wparam
= wparam
;
2514 info
.lparam
= lparam
;
2515 info
.callback
= callback
;
2519 if (is_broadcast(hwnd
))
2521 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2525 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2527 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2529 if (dest_tid
== GetCurrentThreadId())
2531 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2532 call_sendmsg_callback( callback
, hwnd
, msg
, data
, result
);
2535 FIXME( "callback will not be called\n" );
2536 return send_inter_thread_message( dest_tid
, &info
, &result
);
2540 /***********************************************************************
2541 * ReplyMessage (USER32.@)
2543 BOOL WINAPI
ReplyMessage( LRESULT result
)
2545 MESSAGEQUEUE
*queue
= QUEUE_Current();
2546 struct received_message_info
*info
= queue
->receive_info
;
2548 if (!info
) return FALSE
;
2549 reply_message( info
, result
, FALSE
);
2554 /***********************************************************************
2555 * InSendMessage (USER32.@)
2557 BOOL WINAPI
InSendMessage(void)
2559 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2563 /***********************************************************************
2564 * InSendMessageEx (USER32.@)
2566 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2568 MESSAGEQUEUE
*queue
= QUEUE_Current();
2569 struct received_message_info
*info
= queue
->receive_info
;
2571 if (info
) return info
->flags
;
2572 return ISMEX_NOSEND
;
2576 /***********************************************************************
2577 * PostMessageA (USER32.@)
2579 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2581 return PostMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2585 /***********************************************************************
2586 * PostMessageW (USER32.@)
2588 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2590 struct send_message_info info
;
2593 if (is_pointer_message( msg
))
2595 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2599 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2600 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2602 info
.type
= MSG_POSTED
;
2605 info
.wparam
= wparam
;
2606 info
.lparam
= lparam
;
2609 if (is_broadcast(hwnd
))
2611 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2615 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2617 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2619 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2621 return put_message_in_queue( dest_tid
, &info
, NULL
);
2625 /**********************************************************************
2626 * PostThreadMessageA (USER32.@)
2628 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2630 return PostThreadMessageW( thread
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2634 /**********************************************************************
2635 * PostThreadMessageW (USER32.@)
2637 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2639 struct send_message_info info
;
2641 if (is_pointer_message( msg
))
2643 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2646 if (USER_IsExitingThread( thread
)) return TRUE
;
2648 info
.type
= MSG_POSTED
;
2651 info
.wparam
= wparam
;
2652 info
.lparam
= lparam
;
2654 return put_message_in_queue( thread
, &info
, NULL
);
2658 /***********************************************************************
2659 * PostQuitMessage (USER32.@)
2661 void WINAPI
PostQuitMessage( INT exitCode
)
2663 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT
, exitCode
, 0 );
2667 /***********************************************************************
2668 * PeekMessageW (USER32.@)
2670 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2672 MESSAGEQUEUE
*queue
;
2676 /* check for graphics events */
2677 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
2678 USER_Driver
.pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
2680 hwnd
= WIN_GetFullHandle( hwnd
);
2681 locks
= WIN_SuspendWndsLock();
2683 if (!peek_message( &msg
, hwnd
, first
, last
, (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
2685 if (!(flags
& PM_NOYIELD
))
2688 ReleaseThunkLock(&count
);
2689 if (count
) RestoreThunkLock(count
);
2691 WIN_RestoreWndsLock( locks
);
2695 if ((queue
= QUEUE_Current()))
2697 queue
->GetMessageTimeVal
= msg
.time
;
2698 msg
.pt
.x
= LOWORD( queue
->GetMessagePosVal
);
2699 msg
.pt
.y
= HIWORD( queue
->GetMessagePosVal
);
2702 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2704 WIN_RestoreWndsLock( locks
);
2706 /* copy back our internal safe copy of message data to msg_out.
2707 * msg_out is a variable from the *program*, so it can't be used
2708 * internally as it can get "corrupted" by our use of SendMessage()
2709 * (back to the program) inside the message handling itself. */
2712 SetLastError( ERROR_NOACCESS
);
2720 /***********************************************************************
2721 * PeekMessageA (USER32.@)
2723 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2725 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
2726 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2731 /***********************************************************************
2732 * GetMessageW (USER32.@)
2734 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2736 MESSAGEQUEUE
*queue
= QUEUE_Current();
2739 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2742 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2743 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2744 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2745 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2746 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2747 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2749 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
2751 locks
= WIN_SuspendWndsLock();
2753 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
2755 /* wait until one of the bits is set */
2756 unsigned int wake_bits
= 0, changed_bits
= 0;
2759 SERVER_START_REQ( set_queue_mask
)
2761 req
->wake_mask
= QS_SENDMESSAGE
;
2762 req
->changed_mask
= mask
;
2764 if (!wine_server_call( req
))
2766 wake_bits
= reply
->wake_bits
;
2767 changed_bits
= reply
->changed_bits
;
2772 if (changed_bits
& mask
) continue;
2773 if (wake_bits
& QS_SENDMESSAGE
) continue;
2775 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2776 queue
->self
, mask
, wake_bits
, changed_bits
);
2778 ReleaseThunkLock( &dwlc
);
2779 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
2780 USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &queue
->server_queue
, INFINITE
,
2783 WaitForSingleObject( queue
->server_queue
, INFINITE
);
2784 if (dwlc
) RestoreThunkLock( dwlc
);
2787 WIN_RestoreWndsLock( locks
);
2789 return (msg
->message
!= WM_QUIT
);
2793 /***********************************************************************
2794 * GetMessageA (USER32.@)
2796 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2798 GetMessageW( msg
, hwnd
, first
, last
);
2799 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2800 return (msg
->message
!= WM_QUIT
);
2804 /***********************************************************************
2805 * IsDialogMessage (USER32.@)
2806 * IsDialogMessageA (USER32.@)
2808 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2811 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
2812 return IsDialogMessageW( hwndDlg
, &msg
);
2816 /***********************************************************************
2817 * TranslateMessage (USER32.@)
2819 * Implementation of TranslateMessage.
2821 * TranslateMessage translates virtual-key messages into character-messages,
2823 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2824 * ditto replacing WM_* with WM_SYS*
2825 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2826 * by the keyboard driver.
2828 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2829 * return value is nonzero, regardless of the translation.
2832 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2838 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
2839 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
2841 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
2842 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
2844 GetKeyboardState( state
);
2845 /* FIXME : should handle ToUnicode yielding 2 */
2846 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
2849 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2850 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2851 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2852 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2856 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2857 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2858 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2859 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2866 /***********************************************************************
2867 * DispatchMessageA (USER32.@)
2869 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2875 /* Process timer messages */
2876 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2878 if (msg
->lParam
) return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2879 msg
->message
, msg
->wParam
, GetTickCount() );
2882 if (msg
->message
& 0x80000000)
2883 return handle_internal_message( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
2885 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2887 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2890 if (wndPtr
== WND_OTHER_PROCESS
)
2892 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2893 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2896 if (wndPtr
->tid
!= GetCurrentThreadId())
2898 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2899 WIN_ReleasePtr( wndPtr
);
2902 winproc
= wndPtr
->winproc
;
2903 WIN_ReleasePtr( wndPtr
);
2905 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2906 msg
->wParam
, msg
->lParam
);
2907 retval
= CallWindowProcA( winproc
, msg
->hwnd
, msg
->message
,
2908 msg
->wParam
, msg
->lParam
);
2909 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2910 msg
->wParam
, msg
->lParam
);
2912 if (msg
->message
== WM_PAINT
)
2914 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2915 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2916 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
2917 DeleteObject( hrgn
);
2923 /***********************************************************************
2924 * DispatchMessageW (USER32.@) Process a message
2926 * Process the message specified in the structure *_msg_.
2928 * If the lpMsg parameter points to a WM_TIMER message and the
2929 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2930 * points to the function that is called instead of the window
2933 * The message must be valid.
2937 * DispatchMessage() returns the result of the window procedure invoked.
2944 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2950 /* Process timer messages */
2951 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2953 if (msg
->lParam
) return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2954 msg
->message
, msg
->wParam
, GetTickCount() );
2957 if (msg
->message
& 0x80000000)
2958 return handle_internal_message( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
2960 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2962 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2965 if (wndPtr
== WND_OTHER_PROCESS
)
2967 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2968 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2971 if (wndPtr
->tid
!= GetCurrentThreadId())
2973 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2974 WIN_ReleasePtr( wndPtr
);
2977 winproc
= wndPtr
->winproc
;
2978 WIN_ReleasePtr( wndPtr
);
2980 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2981 msg
->wParam
, msg
->lParam
);
2982 retval
= CallWindowProcW( winproc
, msg
->hwnd
, msg
->message
,
2983 msg
->wParam
, msg
->lParam
);
2984 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2985 msg
->wParam
, msg
->lParam
);
2987 if (msg
->message
== WM_PAINT
)
2989 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2990 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2991 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
2992 DeleteObject( hrgn
);
2998 /***********************************************************************
2999 * WaitMessage (USER.112) Suspend thread pending messages
3000 * WaitMessage (USER32.@) Suspend thread pending messages
3002 * WaitMessage() suspends a thread until events appear in the thread's
3005 BOOL WINAPI
WaitMessage(void)
3007 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
3011 /***********************************************************************
3012 * MsgWaitForMultipleObjectsEx (USER32.@)
3014 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
3015 DWORD timeout
, DWORD mask
, DWORD flags
)
3017 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
3019 MESSAGEQUEUE
*msgQueue
;
3021 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
3023 SetLastError( ERROR_INVALID_PARAMETER
);
3027 if (!(msgQueue
= QUEUE_Current())) return WAIT_FAILED
;
3029 /* set the queue mask */
3030 SERVER_START_REQ( set_queue_mask
)
3032 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
3033 req
->changed_mask
= mask
;
3035 wine_server_call( req
);
3039 /* Add the thread event to the handle list */
3040 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
3041 handles
[count
] = msgQueue
->server_queue
;
3043 ReleaseThunkLock( &lock
);
3044 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
3046 ret
= USER_Driver
.pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
3047 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
3050 ret
= WaitForMultipleObjectsEx( count
+1, handles
, flags
& MWMO_WAITALL
,
3051 timeout
, flags
& MWMO_ALERTABLE
);
3052 if (lock
) RestoreThunkLock( lock
);
3057 /***********************************************************************
3058 * MsgWaitForMultipleObjects (USER32.@)
3060 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
3061 BOOL wait_all
, DWORD timeout
, DWORD mask
)
3063 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
3064 wait_all
? MWMO_WAITALL
: 0 );
3068 /***********************************************************************
3069 * WaitForInputIdle (USER32.@)
3071 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
3073 DWORD start_time
, elapsed
, ret
;
3074 HANDLE idle_event
= (HANDLE
)-1;
3076 SERVER_START_REQ( wait_input_idle
)
3078 req
->handle
= hProcess
;
3079 req
->timeout
= dwTimeOut
;
3080 if (!(ret
= wine_server_call_err( req
))) idle_event
= reply
->event
;
3083 if (ret
) return WAIT_FAILED
; /* error */
3084 if (!idle_event
) return 0; /* no event to wait on */
3086 start_time
= GetTickCount();
3089 TRACE("waiting for %p\n", idle_event
);
3092 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
3095 case WAIT_OBJECT_0
+1:
3096 process_sent_messages();
3100 TRACE("timeout or error\n");
3103 TRACE("finished\n");
3106 if (dwTimeOut
!= INFINITE
)
3108 elapsed
= GetTickCount() - start_time
;
3109 if (elapsed
> dwTimeOut
)
3115 return WAIT_TIMEOUT
;
3119 /***********************************************************************
3120 * UserYield (USER.332)
3122 void WINAPI
UserYield16(void)
3126 /* Handle sent messages */
3127 process_sent_messages();
3130 ReleaseThunkLock(&count
);
3134 RestoreThunkLock(count
);
3135 /* Handle sent messages again */
3136 process_sent_messages();
3141 /***********************************************************************
3142 * RegisterWindowMessage (USER.118)
3143 * RegisterWindowMessageA (USER32.@)
3145 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
3147 TRACE("%s\n", str
);
3148 return GlobalAddAtomA( str
);
3152 /***********************************************************************
3153 * RegisterWindowMessageW (USER32.@)
3155 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
3157 TRACE("%p\n", str
);
3158 return GlobalAddAtomW( str
);
3162 /***********************************************************************
3163 * BroadcastSystemMessage (USER32.@)
3164 * BroadcastSystemMessageA (USER32.@)
3166 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3168 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3170 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3171 PostMessageA( HWND_BROADCAST
, msg
, wp
, lp
);
3176 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3182 /***********************************************************************
3183 * BroadcastSystemMessageW (USER32.@)
3185 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3187 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3189 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3190 PostMessageW( HWND_BROADCAST
, msg
, wp
, lp
);
3195 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3201 /***********************************************************************
3202 * SetMessageQueue (USER32.@)
3204 BOOL WINAPI
SetMessageQueue( INT size
)
3206 /* now obsolete the message queue will be expanded dynamically as necessary */
3211 /***********************************************************************
3212 * MessageBeep (USER32.@)
3214 BOOL WINAPI
MessageBeep( UINT i
)
3217 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
3218 if (active
&& USER_Driver
.pBeep
) USER_Driver
.pBeep();
3223 /***********************************************************************
3224 * SetTimer (USER32.@)
3226 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3229 WNDPROC winproc
= 0;
3231 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, WIN_PROC_32A
);
3233 SERVER_START_REQ( set_win_timer
)
3236 req
->msg
= WM_TIMER
;
3238 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3239 req
->lparam
= (unsigned int)winproc
;
3240 if (!wine_server_call_err( req
))
3243 if (!ret
) ret
= TRUE
;
3249 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3254 /***********************************************************************
3255 * SetSystemTimer (USER32.@)
3257 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3260 WNDPROC winproc
= 0;
3262 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, WIN_PROC_32A
);
3264 SERVER_START_REQ( set_win_timer
)
3267 req
->msg
= WM_SYSTIMER
;
3269 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3270 req
->lparam
= (unsigned int)winproc
;
3271 if (!wine_server_call_err( req
))
3274 if (!ret
) ret
= TRUE
;
3280 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3285 /***********************************************************************
3286 * KillTimer (USER32.@)
3288 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
3292 TRACE("%p %d\n", hwnd
, id
);
3294 SERVER_START_REQ( kill_win_timer
)
3297 req
->msg
= WM_TIMER
;
3299 ret
= !wine_server_call_err( req
);
3306 /***********************************************************************
3307 * KillSystemTimer (USER32.@)
3309 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
3313 TRACE("%p %d\n", hwnd
, id
);
3315 SERVER_START_REQ( kill_win_timer
)
3318 req
->msg
= WM_SYSTIMER
;
3320 ret
= !wine_server_call_err( req
);
3327 /**********************************************************************
3328 * AttachThreadInput (USER32.@)
3330 * Attaches the input processing mechanism of one thread to that of
3333 BOOL WINAPI
AttachThreadInput( DWORD from
, DWORD to
, BOOL attach
)
3337 SERVER_START_REQ( attach_thread_input
)
3339 req
->tid_from
= from
;
3341 req
->attach
= attach
;
3342 ret
= !wine_server_call_err( req
);
3349 /**********************************************************************
3350 * GetGUIThreadInfo (USER32.@)
3352 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
3356 SERVER_START_REQ( get_thread_input
)
3359 if ((ret
= !wine_server_call_err( req
)))
3362 info
->hwndActive
= reply
->active
;
3363 info
->hwndFocus
= reply
->focus
;
3364 info
->hwndCapture
= reply
->capture
;
3365 info
->hwndMenuOwner
= reply
->menu_owner
;
3366 info
->hwndMoveSize
= reply
->move_size
;
3367 info
->hwndCaret
= reply
->caret
;
3368 info
->rcCaret
.left
= reply
->rect
.left
;
3369 info
->rcCaret
.top
= reply
->rect
.top
;
3370 info
->rcCaret
.right
= reply
->rect
.right
;
3371 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
3372 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
3373 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
3374 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
3382 /**********************************************************************
3383 * GetKeyState (USER32.@)
3385 * An application calls the GetKeyState function in response to a
3386 * keyboard-input message. This function retrieves the state of the key
3387 * at the time the input message was generated.
3389 SHORT WINAPI
GetKeyState(INT vkey
)
3393 SERVER_START_REQ( get_key_state
)
3395 req
->tid
= GetCurrentThreadId();
3397 if (!wine_server_call( req
)) retval
= (signed char)reply
->state
;
3400 TRACE("key (0x%x) -> %x\n", vkey
, retval
);
3405 /**********************************************************************
3406 * GetKeyboardState (USER32.@)
3408 BOOL WINAPI
GetKeyboardState( LPBYTE state
)
3412 TRACE("(%p)\n", state
);
3414 memset( state
, 0, 256 );
3415 SERVER_START_REQ( get_key_state
)
3417 req
->tid
= GetCurrentThreadId();
3419 wine_server_set_reply( req
, state
, 256 );
3420 ret
= !wine_server_call_err( req
);
3427 /**********************************************************************
3428 * SetKeyboardState (USER32.@)
3430 BOOL WINAPI
SetKeyboardState( LPBYTE state
)
3434 TRACE("(%p)\n", state
);
3436 SERVER_START_REQ( set_key_state
)
3438 req
->tid
= GetCurrentThreadId();
3439 wine_server_add_data( req
, state
, 256 );
3440 ret
= !wine_server_call_err( req
);
3446 /******************************************************************
3447 * IsHungAppWindow (USER32.@)
3450 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
3453 return !SendMessageTimeoutA(hWnd
, WM_NULL
, 0, 0, SMTO_ABORTIFHUNG
, 5000, &dwResult
);
3456 /******************************************************************
3457 * GetLastInputInfo (USER32.@)
3459 BOOL WINAPI
GetLastInputInfo(PLASTINPUTINFO plii
)
3461 FIXME("%p\n", plii
);