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"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msg);
44 WINE_DECLARE_DEBUG_CHANNEL(relay);
46 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
47 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
49 #define MAX_PACK_COUNT 4
51 /* description of the data fields that need to be packed along with a sent message */
55 const void *data[MAX_PACK_COUNT];
56 size_t size[MAX_PACK_COUNT];
59 /* info about the message currently being received by the current thread */
60 struct received_message_info
62 enum message_type type;
64 UINT flags; /* InSendMessageEx return flags */
67 /* structure to group all parameters for sent messages of the various kinds */
68 struct send_message_info
70 enum message_type type;
75 UINT flags; /* flags for SendMessageTimeout */
76 UINT timeout; /* timeout for SendMessageTimeout */
77 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
78 ULONG_PTR data; /* callback data */
82 /* flag for messages that contain pointers */
83 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
85 #define SET(msg) (1 << ((msg) & 31))
87 static const unsigned int message_pointer_flags[] =
90 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
91 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
93 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
96 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
97 SET(WM_NOTIFY) | SET(WM_HELP),
99 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
101 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
103 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
105 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
107 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO),
113 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
114 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
115 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
119 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
120 SET(LB_DIR) | SET(LB_FINDSTRING) |
121 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
123 SET(LB_FINDSTRINGEXACT),
129 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
131 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
132 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
146 SET(WM_ASKCBFORMATNAME)
149 /* flags for messages that contain Unicode strings */
150 static const unsigned int message_unicode_flags[] =
153 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
154 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
166 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
170 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
174 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
175 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
179 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
180 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
182 SET(LB_FINDSTRINGEXACT),
204 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
207 /* check whether a given message type includes pointers */
208 inline static int is_pointer_message( UINT message )
210 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
211 return (message_pointer_flags[message / 32] & SET(message)) != 0;
214 /* check whether a given message type contains Unicode (or ASCII) chars */
215 inline static int is_unicode_message( UINT message )
217 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
218 return (message_unicode_flags[message / 32] & SET(message)) != 0;
223 /* add a data field to a packed message */
224 inline static void push_data( struct packed_message *data, const void *ptr, size_t size )
226 data->data[data->count] = ptr;
227 data->size[data->count] = size;
231 /* add a string to a packed message */
232 inline static void push_string( struct packed_message *data, LPCWSTR str )
234 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
237 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
238 inline static void *get_data( void **buffer, size_t size )
241 *buffer = (char *)*buffer + size;
245 /* make sure that the buffer contains a valid null-terminated Unicode string */
246 inline static BOOL check_string( LPCWSTR str, size_t size )
248 for (size /= sizeof(WCHAR); size; size--, str++)
249 if (!*str) return TRUE;
253 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
254 inline static void *get_buffer_space( void **buffer, size_t size )
257 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
258 HeapFree( GetProcessHeap(), 0, *buffer );
263 /* retrieve a string pointer from packed data */
264 inline static LPWSTR get_string( void **buffer )
266 return get_data( buffer, (strlenW( (LPWSTR)*buffer ) + 1) * sizeof(WCHAR) );
269 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
270 inline static BOOL combobox_has_strings( HWND hwnd )
272 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
273 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
276 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
277 inline static BOOL listbox_has_strings( HWND hwnd )
279 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
280 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
284 /***********************************************************************
285 * broadcast_message_callback
287 * Helper callback for broadcasting messages.
289 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
291 struct send_message_info *info = (struct send_message_info *)lparam;
292 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
296 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
297 info->flags, info->timeout, NULL );
300 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
301 info->flags, info->timeout, NULL );
304 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
307 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
308 info->callback, info->data );
311 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
314 ERR( "bad type %d\n", info->type );
321 /***********************************************************************
324 * Convert the wparam of an ASCII message to Unicode.
326 static WPARAM map_wparam_AtoW( UINT message, WPARAM wparam )
331 case EM_SETPASSWORDCHAR:
338 char ch = LOWORD(wparam);
340 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
341 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
348 ch[0] = (wparam >> 8);
349 ch[1] = (wparam & 0xff);
350 MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
351 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
359 /***********************************************************************
362 * Convert the wparam of a Unicode message to ASCII.
364 static WPARAM map_wparam_WtoA( UINT message, WPARAM wparam )
369 case EM_SETPASSWORDCHAR:
376 WCHAR wch = LOWORD(wparam);
378 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
379 wparam = MAKEWPARAM( ch, HIWORD(wparam) );
384 WCHAR wch = LOWORD(wparam);
388 WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL );
389 wparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wparam) );
397 /***********************************************************************
400 * Pack a message for sending to another process.
401 * Return the size of the data we expect in the message reply.
402 * Set data->count to -1 if there is an error.
404 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
405 struct packed_message *data )
413 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
414 push_data( data, cs, sizeof(*cs) );
415 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
416 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
420 case WM_ASKCBFORMATNAME:
421 return wparam * sizeof(WCHAR);
422 case WM_WININICHANGE:
423 if (lparam) push_string(data, (LPWSTR)lparam );
426 case WM_DEVMODECHANGE:
431 push_string( data, (LPWSTR)lparam );
433 case WM_GETMINMAXINFO:
434 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
435 return sizeof(MINMAXINFO);
437 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
440 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
441 return sizeof(MEASUREITEMSTRUCT);
443 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
446 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
448 case WM_WINDOWPOSCHANGING:
449 case WM_WINDOWPOSCHANGED:
450 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
451 return sizeof(WINDOWPOS);
454 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
455 push_data( data, cp, sizeof(*cp) );
456 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
460 /* WM_NOTIFY cannot be sent across processes (MSDN) */
464 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
466 case WM_STYLECHANGING:
467 case WM_STYLECHANGED:
468 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
473 push_data( data, (RECT *)lparam, sizeof(RECT) );
478 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
479 push_data( data, nc, sizeof(*nc) );
480 push_data( data, nc->lppos, sizeof(*nc->lppos) );
481 return sizeof(*nc) + sizeof(*nc->lppos);
484 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
486 case SBM_SETSCROLLINFO:
487 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
489 case SBM_GETSCROLLINFO:
490 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
491 return sizeof(SCROLLINFO);
497 if (wparam) size += sizeof(DWORD);
498 if (lparam) size += sizeof(DWORD);
503 case CB_GETDROPPEDCONTROLRECT:
507 push_data( data, (RECT *)lparam, sizeof(RECT) );
511 WORD *pw = (WORD *)lparam;
512 push_data( data, pw, sizeof(*pw) );
513 return *pw * sizeof(WCHAR);
517 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
520 case CB_INSERTSTRING:
522 case CB_FINDSTRINGEXACT:
523 case CB_SELECTSTRING:
524 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
527 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
528 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
530 case LB_INSERTSTRING:
532 case LB_FINDSTRINGEXACT:
533 case LB_SELECTSTRING:
534 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
537 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
538 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
540 return wparam * sizeof(UINT);
542 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
543 return sizeof(MDINEXTMENU);
546 push_data( data, (RECT *)lparam, sizeof(RECT) );
550 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
551 push_data( data, cs, sizeof(*cs) );
552 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
553 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
556 case WM_MDIGETACTIVE:
557 if (lparam) return sizeof(BOOL);
559 case WM_WINE_SETWINDOWPOS:
560 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
562 case WM_WINE_KEYBOARD_LL_HOOK:
563 push_data( data, (KBDLLHOOKSTRUCT *)lparam, sizeof(KBDLLHOOKSTRUCT) );
565 case WM_WINE_MOUSE_LL_HOOK:
566 push_data( data, (MSLLHOOKSTRUCT *)lparam, sizeof(MSLLHOOKSTRUCT) );
569 /* these contain an HFONT */
572 /* these contain an HDC */
575 case WM_ICONERASEBKGND:
577 case WM_CTLCOLORMSGBOX:
578 case WM_CTLCOLOREDIT:
579 case WM_CTLCOLORLISTBOX:
582 case WM_CTLCOLORSCROLLBAR:
583 case WM_CTLCOLORSTATIC:
586 /* these contain an HGLOBAL */
587 case WM_PAINTCLIPBOARD:
588 case WM_SIZECLIPBOARD:
589 /* these contain HICON */
592 case WM_QUERYDRAGICON:
593 case WM_QUERYPARKICON:
594 /* these contain pointers */
596 case WM_QUERYDROPOBJECT:
600 case WM_DEVICECHANGE:
601 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
609 /***********************************************************************
612 * Unpack a message received from another process.
614 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
615 void **buffer, size_t size )
624 CREATESTRUCTW *cs = *buffer;
625 WCHAR *str = (WCHAR *)(cs + 1);
626 if (size < sizeof(*cs)) return FALSE;
628 if (HIWORD(cs->lpszName))
630 if (!check_string( str, size )) return FALSE;
632 size -= (strlenW(str) + 1) * sizeof(WCHAR);
633 str += strlenW(str) + 1;
635 if (HIWORD(cs->lpszClass))
637 if (!check_string( str, size )) return FALSE;
643 case WM_ASKCBFORMATNAME:
644 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
646 case WM_WININICHANGE:
647 if (!*lparam) return TRUE;
650 case WM_DEVMODECHANGE:
655 if (!check_string( *buffer, size )) return FALSE;
657 case WM_GETMINMAXINFO:
658 minsize = sizeof(MINMAXINFO);
661 minsize = sizeof(DRAWITEMSTRUCT);
664 minsize = sizeof(MEASUREITEMSTRUCT);
667 minsize = sizeof(DELETEITEMSTRUCT);
670 minsize = sizeof(COMPAREITEMSTRUCT);
672 case WM_WINDOWPOSCHANGING:
673 case WM_WINDOWPOSCHANGED:
674 case WM_WINE_SETWINDOWPOS:
675 minsize = sizeof(WINDOWPOS);
679 COPYDATASTRUCT *cp = *buffer;
680 if (size < sizeof(*cp)) return FALSE;
683 minsize = sizeof(*cp) + cp->cbData;
689 /* WM_NOTIFY cannot be sent across processes (MSDN) */
692 minsize = sizeof(HELPINFO);
694 case WM_STYLECHANGING:
695 case WM_STYLECHANGED:
696 minsize = sizeof(STYLESTRUCT);
699 if (!*wparam) minsize = sizeof(RECT);
702 NCCALCSIZE_PARAMS *nc = *buffer;
703 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
704 nc->lppos = (WINDOWPOS *)(nc + 1);
708 if (!*lparam) return TRUE;
709 minsize = sizeof(MSG);
711 case SBM_SETSCROLLINFO:
712 minsize = sizeof(SCROLLINFO);
714 case SBM_GETSCROLLINFO:
715 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
720 if (*wparam || *lparam)
722 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
723 if (*wparam) *wparam = (WPARAM)*buffer;
724 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
729 case CB_GETDROPPEDCONTROLRECT:
730 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
734 minsize = sizeof(RECT);
739 if (size < sizeof(WORD)) return FALSE;
740 len = *(WORD *)*buffer;
741 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
742 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
747 if (!*wparam) return TRUE;
748 minsize = *wparam * sizeof(UINT);
751 case CB_INSERTSTRING:
753 case CB_FINDSTRINGEXACT:
754 case CB_SELECTSTRING:
756 case LB_INSERTSTRING:
758 case LB_FINDSTRINGEXACT:
759 case LB_SELECTSTRING:
760 if (!*buffer) return TRUE;
761 if (!check_string( *buffer, size )) return FALSE;
765 size = sizeof(ULONG_PTR);
766 if (combobox_has_strings( hwnd ))
767 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
768 if (!get_buffer_space( buffer, size )) return FALSE;
773 size = sizeof(ULONG_PTR);
774 if (listbox_has_strings( hwnd ))
775 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
776 if (!get_buffer_space( buffer, size )) return FALSE;
780 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
783 minsize = sizeof(MDINEXTMENU);
784 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
788 minsize = sizeof(RECT);
789 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
793 MDICREATESTRUCTW *cs = *buffer;
794 WCHAR *str = (WCHAR *)(cs + 1);
795 if (size < sizeof(*cs)) return FALSE;
797 if (HIWORD(cs->szTitle))
799 if (!check_string( str, size )) return FALSE;
801 size -= (strlenW(str) + 1) * sizeof(WCHAR);
802 str += strlenW(str) + 1;
804 if (HIWORD(cs->szClass))
806 if (!check_string( str, size )) return FALSE;
811 case WM_MDIGETACTIVE:
812 if (!*lparam) return TRUE;
813 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
815 case WM_WINE_KEYBOARD_LL_HOOK:
816 minsize = sizeof(KBDLLHOOKSTRUCT);
818 case WM_WINE_MOUSE_LL_HOOK:
819 minsize = sizeof(MSLLHOOKSTRUCT);
822 /* these contain an HFONT */
825 /* these contain an HDC */
828 case WM_ICONERASEBKGND:
830 case WM_CTLCOLORMSGBOX:
831 case WM_CTLCOLOREDIT:
832 case WM_CTLCOLORLISTBOX:
835 case WM_CTLCOLORSCROLLBAR:
836 case WM_CTLCOLORSTATIC:
839 /* these contain an HGLOBAL */
840 case WM_PAINTCLIPBOARD:
841 case WM_SIZECLIPBOARD:
842 /* these contain HICON */
845 case WM_QUERYDRAGICON:
846 case WM_QUERYPARKICON:
847 /* these contain pointers */
849 case WM_QUERYDROPOBJECT:
853 case WM_DEVICECHANGE:
854 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
858 return TRUE; /* message doesn't need any unpacking */
861 /* default exit for most messages: check minsize and store buffer in lparam */
862 if (size < minsize) return FALSE;
863 *lparam = (LPARAM)*buffer;
868 /***********************************************************************
871 * Pack a reply to a message for sending to another process.
873 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
874 LRESULT res, struct packed_message *data )
881 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
886 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
888 case WM_GETMINMAXINFO:
889 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
892 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
894 case WM_WINDOWPOSCHANGING:
895 case WM_WINDOWPOSCHANGED:
896 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
899 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
901 case SBM_GETSCROLLINFO:
902 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
906 case CB_GETDROPPEDCONTROLRECT:
909 push_data( data, (RECT *)lparam, sizeof(RECT) );
913 WORD *ptr = (WORD *)lparam;
914 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
918 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
920 case WM_MDIGETACTIVE:
921 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
925 push_data( data, (RECT *)lparam, sizeof(RECT) );
928 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
929 push_data( data, nc, sizeof(*nc) );
930 push_data( data, nc->lppos, sizeof(*nc->lppos) );
936 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
937 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
940 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
943 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
945 case WM_ASKCBFORMATNAME:
946 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
952 /***********************************************************************
955 * Unpack a message reply received from another process.
957 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
958 void *buffer, size_t size )
965 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
966 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
967 memcpy( cs, buffer, min( sizeof(*cs), size ));
968 cs->lpszName = name; /* restore the original pointers */
969 cs->lpszClass = class;
973 case WM_ASKCBFORMATNAME:
974 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
976 case WM_GETMINMAXINFO:
977 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
980 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
982 case WM_WINDOWPOSCHANGING:
983 case WM_WINDOWPOSCHANGED:
984 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
987 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
989 case SBM_GETSCROLLINFO:
990 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
993 case CB_GETDROPPEDCONTROLRECT:
997 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1000 size = min( size, (size_t)*(WORD *)lparam );
1001 memcpy( (WCHAR *)lparam, buffer, size );
1003 case LB_GETSELITEMS:
1004 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1008 memcpy( (WCHAR *)lparam, buffer, size );
1011 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1013 case WM_MDIGETACTIVE:
1014 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1018 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1021 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1022 WINDOWPOS *wp = nc->lppos;
1023 memcpy( nc, buffer, min( sizeof(*nc), size ));
1024 if (size > sizeof(*nc))
1026 size -= sizeof(*nc);
1027 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1029 nc->lppos = wp; /* restore the original pointer */
1037 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1038 if (size <= sizeof(DWORD)) break;
1039 size -= sizeof(DWORD);
1040 buffer = (DWORD *)buffer + 1;
1042 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1046 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1047 LPCWSTR title = cs->szTitle, class = cs->szClass;
1048 memcpy( cs, buffer, min( sizeof(*cs), size ));
1049 cs->szTitle = title; /* restore the original pointers */
1050 cs->szClass = class;
1054 ERR( "should not happen: unexpected message %x\n", message );
1060 /***********************************************************************
1063 * Send a reply to a sent message.
1065 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1067 struct packed_message data;
1068 int i, replied = info->flags & ISMEX_REPLIED;
1070 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1071 if (!remove && replied) return; /* replied already */
1074 info->flags |= ISMEX_REPLIED;
1076 if (info->type == MSG_OTHER_PROCESS && !replied)
1078 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1079 info->msg.lParam, result, &data );
1082 SERVER_START_REQ( reply_message )
1084 req->type = info->type;
1085 req->result = result;
1086 req->remove = remove;
1087 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1088 wine_server_call( req );
1094 /***********************************************************************
1095 * handle_internal_message
1097 * Handle an internal Wine message instead of calling the window proc.
1099 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1101 if (hwnd == GetDesktopWindow()) return 0;
1104 case WM_WINE_DESTROYWINDOW:
1105 return WIN_DestroyWindow( hwnd );
1106 case WM_WINE_SETWINDOWPOS:
1107 return USER_Driver.pSetWindowPos( (WINDOWPOS *)lparam );
1108 case WM_WINE_SHOWWINDOW:
1109 return ShowWindow( hwnd, wparam );
1110 case WM_WINE_SETPARENT:
1111 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1112 case WM_WINE_SETWINDOWLONG:
1113 return (LRESULT)SetWindowLongW( hwnd, wparam, lparam );
1114 case WM_WINE_ENABLEWINDOW:
1115 return EnableWindow( hwnd, wparam );
1116 case WM_WINE_SETACTIVEWINDOW:
1117 return (LRESULT)SetActiveWindow( (HWND)wparam );
1118 case WM_WINE_KEYBOARD_LL_HOOK:
1119 return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
1120 case WM_WINE_MOUSE_LL_HOOK:
1121 return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
1123 FIXME( "unknown internal message %x\n", msg );
1128 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1129 * to the memory handle, we keep track (in the server side) of all pairs of handle
1130 * used (the client passes its value and the content of the memory handle), and
1131 * the server stored both values (the client, and the local one, created after the
1132 * content). When a ACK message is generated, the list of pair is searched for a
1133 * matching pair, so that the client memory handle can be returned.
1136 HGLOBAL client_hMem;
1137 HGLOBAL server_hMem;
1140 static struct DDE_pair* dde_pairs;
1141 static int dde_num_alloc;
1142 static int dde_num_used;
1144 static CRITICAL_SECTION dde_crst;
1145 static CRITICAL_SECTION_DEBUG critsect_debug =
1148 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1149 0, 0, { 0, (DWORD)(__FILE__ ": dde_crst") }
1151 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1153 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1158 EnterCriticalSection(&dde_crst);
1160 /* now remember the pair of hMem on both sides */
1161 if (dde_num_used == dde_num_alloc)
1163 struct DDE_pair* tmp;
1165 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1166 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1168 tmp = HeapAlloc( GetProcessHeap(), 0,
1169 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1173 LeaveCriticalSection(&dde_crst);
1177 /* zero out newly allocated part */
1178 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1179 dde_num_alloc += GROWBY;
1182 for (i = 0; i < dde_num_alloc; i++)
1184 if (dde_pairs[i].server_hMem == 0)
1186 dde_pairs[i].client_hMem = chm;
1187 dde_pairs[i].server_hMem = shm;
1192 LeaveCriticalSection(&dde_crst);
1196 static HGLOBAL dde_get_pair(HGLOBAL shm)
1201 EnterCriticalSection(&dde_crst);
1202 for (i = 0; i < dde_num_alloc; i++)
1204 if (dde_pairs[i].server_hMem == shm)
1206 /* free this pair */
1207 dde_pairs[i].server_hMem = 0;
1209 ret = dde_pairs[i].client_hMem;
1213 LeaveCriticalSection(&dde_crst);
1217 /***********************************************************************
1220 * Post a DDE message
1222 static BOOL post_dde_message( DWORD dest_tid, struct packed_message *data, const struct send_message_info *info )
1228 HGLOBAL hunlock = 0;
1232 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1238 /* DDE messages which don't require packing are:
1247 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1248 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1251 /* send back the value of h on the other side */
1252 push_data( data, &h, sizeof(HGLOBAL) );
1254 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo, uiHi, (DWORD)h );
1259 /* uiHi should contain either an atom or 0 */
1260 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1261 lp = MAKELONG( uiLo, uiHi );
1270 size = GlobalSize( (HGLOBAL)uiLo ) ;
1271 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1272 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1273 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1277 else if (info->msg != WM_DDE_DATA) return FALSE;
1282 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1284 DDEDATA *dde_data = (DDEDATA *)ptr;
1285 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1286 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1287 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1288 push_data( data, ptr, size );
1289 hunlock = (HGLOBAL)uiLo;
1292 TRACE( "send ddepack %u %x\n", size, uiHi );
1294 case WM_DDE_EXECUTE:
1297 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1299 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1300 /* so that the other side can send it back on ACK */
1302 hunlock = (HGLOBAL)info->lparam;
1307 SERVER_START_REQ( send_message )
1310 req->type = info->type;
1312 req->win = info->hwnd;
1313 req->msg = info->msg;
1314 req->wparam = info->wparam;
1316 req->time = GetCurrentTime();
1318 for (i = 0; i < data->count; i++)
1319 wine_server_add_data( req, data->data[i], data->size[i] );
1320 if ((res = wine_server_call( req )))
1322 if (res == STATUS_INVALID_PARAMETER)
1323 /* FIXME: find a STATUS_ value for this one */
1324 SetLastError( ERROR_INVALID_THREAD_ID );
1326 SetLastError( RtlNtStatusToDosError(res) );
1329 FreeDDElParam(info->msg, info->lparam);
1332 if (hunlock) GlobalUnlock(hunlock);
1337 /***********************************************************************
1338 * unpack_dde_message
1340 * Unpack a posted DDE message received from another process.
1342 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1343 void **buffer, size_t size )
1354 /* hMem is being passed */
1355 if (size != sizeof(HGLOBAL)) return FALSE;
1356 if (!buffer || !*buffer) return FALSE;
1358 memcpy( &hMem, *buffer, size );
1360 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1364 uiLo = LOWORD( *lparam );
1365 uiHi = HIWORD( *lparam );
1366 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1368 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1373 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1375 TRACE( "recv ddepack %u %x\n", size, uiHi );
1378 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1379 if (hMem && (ptr = GlobalLock( hMem )))
1381 memcpy( ptr, *buffer, size );
1382 GlobalUnlock( hMem );
1388 *lparam = PackDDElParam( message, uiLo, uiHi );
1390 case WM_DDE_EXECUTE:
1393 if (!buffer || !*buffer) return FALSE;
1394 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1395 if (hMem && (ptr = GlobalLock( hMem )))
1397 memcpy( ptr, *buffer, size );
1398 GlobalUnlock( hMem );
1399 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1400 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1406 } else return FALSE;
1407 *lparam = (LPARAM)hMem;
1413 /***********************************************************************
1416 * Call a window procedure and the corresponding hooks.
1418 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1419 BOOL unicode, BOOL same_thread )
1424 CWPRETSTRUCT cwpret;
1425 MESSAGEQUEUE *queue = QUEUE_Current();
1427 if (queue->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1428 queue->recursion_count++;
1430 if (msg & 0x80000000)
1432 result = handle_internal_message( hwnd, msg, wparam, lparam );
1436 /* first the WH_CALLWNDPROC hook */
1437 hwnd = WIN_GetFullHandle( hwnd );
1438 cwp.lParam = lparam;
1439 cwp.wParam = wparam;
1442 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1444 /* now call the window procedure */
1447 if (!(winproc = (WNDPROC)GetWindowLongW( hwnd, GWL_WNDPROC ))) goto done;
1448 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1452 if (!(winproc = (WNDPROC)GetWindowLongA( hwnd, GWL_WNDPROC ))) goto done;
1453 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1456 /* and finally the WH_CALLWNDPROCRET hook */
1457 cwpret.lResult = result;
1458 cwpret.lParam = lparam;
1459 cwpret.wParam = wparam;
1460 cwpret.message = msg;
1462 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1464 queue->recursion_count--;
1469 /***********************************************************************
1470 * process_hardware_message
1472 * Process a hardware message; return TRUE if message should be passed on to the app
1474 static BOOL process_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd,
1475 UINT first, UINT last, BOOL remove )
1479 if (!MSG_process_raw_hardware_message( msg, extra_info, hwnd, first, last, remove ))
1482 ret = MSG_process_cooked_hardware_message( msg, extra_info, remove );
1484 /* tell the server we have passed it to the app
1485 * (even though we may end up dropping it later on)
1487 SERVER_START_REQ( reply_message )
1489 req->type = MSG_HARDWARE;
1491 req->remove = remove || !ret;
1492 wine_server_call( req );
1499 /***********************************************************************
1500 * call_sendmsg_callback
1502 * Call the callback function of SendMessageCallback.
1504 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1505 ULONG_PTR data, LRESULT result )
1507 if (TRACE_ON(relay))
1508 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1509 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1511 callback( hwnd, msg, data, result );
1512 if (TRACE_ON(relay))
1513 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1514 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1519 /***********************************************************************
1522 * Peek for a message matching the given parameters. Return FALSE if none available.
1523 * All pending sent messages are processed before returning.
1525 BOOL MSG_peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1528 ULONG_PTR extra_info = 0;
1529 MESSAGEQUEUE *queue = QUEUE_Current();
1530 struct received_message_info info, *old_info;
1532 if (!first && !last) last = ~0;
1537 void *buffer = NULL;
1538 size_t size = 0, buffer_size = 0;
1540 do /* loop while buffer is too small */
1542 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1544 SERVER_START_REQ( get_message )
1547 req->get_win = hwnd;
1548 req->get_first = first;
1549 req->get_last = last;
1550 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1551 if (!(res = wine_server_call( req )))
1553 size = wine_server_reply_size( reply );
1554 info.type = reply->type;
1555 info.msg.hwnd = reply->win;
1556 info.msg.message = reply->msg;
1557 info.msg.wParam = reply->wparam;
1558 info.msg.lParam = reply->lparam;
1559 info.msg.time = reply->time;
1560 info.msg.pt.x = reply->x;
1561 info.msg.pt.y = reply->y;
1562 extra_info = reply->info;
1566 if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
1567 buffer_size = reply->total;
1571 } while (res == STATUS_BUFFER_OVERFLOW);
1573 if (res) return FALSE;
1575 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1576 info.type, info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1577 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1583 info.flags = ISMEX_SEND;
1586 info.flags = ISMEX_NOTIFY;
1589 info.flags = ISMEX_CALLBACK;
1591 case MSG_CALLBACK_RESULT:
1592 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
1593 info.msg.message, extra_info, info.msg.lParam );
1595 case MSG_OTHER_PROCESS:
1596 info.flags = ISMEX_SEND;
1597 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1598 &info.msg.lParam, &buffer, size ))
1600 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1601 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
1602 info.msg.wParam, info.msg.lParam, size );
1604 reply_message( &info, 0, TRUE );
1609 if (!process_hardware_message( &info.msg, extra_info,
1610 hwnd, first, last, flags & GET_MSG_REMOVE ))
1612 TRACE("dropping msg %x\n", info.msg.message );
1613 goto next; /* ignore it */
1615 queue->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
1618 queue->GetMessageExtraInfoVal = extra_info;
1619 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
1621 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1622 &info.msg.lParam, &buffer, size ))
1624 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1625 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1626 info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
1627 goto next; /* ignore it */
1631 if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
1635 /* if we get here, we have a sent message; call the window procedure */
1636 old_info = queue->receive_info;
1637 queue->receive_info = &info;
1638 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
1639 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
1640 reply_message( &info, result, TRUE );
1641 queue->receive_info = old_info;
1643 if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
1648 /***********************************************************************
1649 * wait_message_reply
1651 * Wait until a sent message gets replied to.
1653 static void wait_message_reply( UINT flags )
1655 MESSAGEQUEUE *queue;
1657 if (!(queue = QUEUE_Current())) return;
1661 unsigned int wake_bits = 0, changed_bits = 0;
1664 SERVER_START_REQ( set_queue_mask )
1666 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
1667 req->changed_mask = req->wake_mask;
1669 if (!wine_server_call( req ))
1671 wake_bits = reply->wake_bits;
1672 changed_bits = reply->changed_bits;
1677 if (wake_bits & QS_SMRESULT) return; /* got a result */
1678 if (wake_bits & QS_SENDMESSAGE)
1680 /* Process the sent message immediately */
1682 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
1686 /* now wait for it */
1688 ReleaseThunkLock( &dwlc );
1690 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
1691 res = USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue,
1694 res = WaitForSingleObject( queue->server_queue, INFINITE );
1696 if (dwlc) RestoreThunkLock( dwlc );
1700 /***********************************************************************
1701 * put_message_in_queue
1703 * Put a sent message into the destination queue.
1704 * For inter-process message, reply_size is set to expected size of reply data.
1706 static BOOL put_message_in_queue( DWORD dest_tid, const struct send_message_info *info,
1707 size_t *reply_size )
1709 struct packed_message data;
1711 int i, timeout = -1;
1713 if (info->type != MSG_NOTIFY &&
1714 info->type != MSG_CALLBACK &&
1715 info->type != MSG_POSTED &&
1716 info->timeout != INFINITE)
1717 timeout = info->timeout;
1720 if (info->type == MSG_OTHER_PROCESS)
1722 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
1723 if (data.count == -1)
1725 WARN( "cannot pack message %x\n", info->msg );
1729 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
1731 return post_dde_message( dest_tid, &data, info );
1734 SERVER_START_REQ( send_message )
1737 req->type = info->type;
1739 req->win = info->hwnd;
1740 req->msg = info->msg;
1741 req->wparam = info->wparam;
1742 req->lparam = info->lparam;
1743 req->time = GetCurrentTime();
1744 req->timeout = timeout;
1746 if (info->type == MSG_CALLBACK)
1748 req->callback = info->callback;
1749 req->info = info->data;
1752 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
1753 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1754 if ((res = wine_server_call( req )))
1756 if (res == STATUS_INVALID_PARAMETER)
1757 /* FIXME: find a STATUS_ value for this one */
1758 SetLastError( ERROR_INVALID_THREAD_ID );
1760 SetLastError( RtlNtStatusToDosError(res) );
1768 /***********************************************************************
1771 * Retrieve a message reply from the server.
1773 static LRESULT retrieve_reply( const struct send_message_info *info,
1774 size_t reply_size, LRESULT *result )
1777 void *reply_data = NULL;
1781 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
1783 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
1787 SERVER_START_REQ( get_message_reply )
1790 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
1791 if (!(status = wine_server_call( req ))) *result = reply->result;
1792 reply_size = wine_server_reply_size( reply );
1795 if (!status && reply_size)
1796 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
1798 if (reply_data) HeapFree( GetProcessHeap(), 0, reply_data );
1800 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1801 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
1802 info->lparam, *result, status );
1804 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
1805 if (status) SetLastError( RtlNtStatusToDosError(status) );
1810 /***********************************************************************
1811 * send_inter_thread_message
1813 static LRESULT send_inter_thread_message( DWORD dest_tid, const struct send_message_info *info,
1818 size_t reply_size = 0;
1820 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
1821 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
1823 if (!put_message_in_queue( dest_tid, info, &reply_size )) return 0;
1825 /* there's no reply to wait for on notify/callback messages */
1826 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
1828 locks = WIN_SuspendWndsLock();
1830 wait_message_reply( info->flags );
1831 ret = retrieve_reply( info, reply_size, res_ptr );
1833 WIN_RestoreWndsLock( locks );
1838 /***********************************************************************
1839 * MSG_SendInternalMessageTimeout
1841 * Same as SendMessageTimeoutW but sends the message to a specific thread
1842 * without requiring a window handle. Only works for internal Wine messages.
1844 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
1845 UINT msg, WPARAM wparam, LPARAM lparam,
1846 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1848 struct send_message_info info;
1849 LRESULT ret, result;
1851 assert( msg & 0x80000000 ); /* must be an internal Wine message */
1853 info.type = MSG_UNICODE;
1856 info.wparam = wparam;
1857 info.lparam = lparam;
1859 info.timeout = timeout;
1861 if (USER_IsExitingThread( dest_tid )) return 0;
1863 if (dest_tid == GetCurrentThreadId())
1865 result = handle_internal_message( 0, msg, wparam, lparam );
1870 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1871 ret = send_inter_thread_message( dest_tid, &info, &result );
1873 if (ret && res_ptr) *res_ptr = result;
1878 /***********************************************************************
1879 * SendMessageTimeoutW (USER32.@)
1881 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1882 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1884 struct send_message_info info;
1885 DWORD dest_tid, dest_pid;
1886 LRESULT ret, result;
1888 info.type = MSG_UNICODE;
1891 info.wparam = wparam;
1892 info.lparam = lparam;
1894 info.timeout = timeout;
1896 if (is_broadcast(hwnd))
1898 EnumWindows( broadcast_message_callback, (LPARAM)&info );
1899 if (res_ptr) *res_ptr = 1;
1903 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
1905 if (USER_IsExitingThread( dest_tid )) return 0;
1907 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
1909 if (dest_tid == GetCurrentThreadId())
1911 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
1916 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1917 ret = send_inter_thread_message( dest_tid, &info, &result );
1920 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
1921 if (ret && res_ptr) *res_ptr = result;
1926 /***********************************************************************
1927 * SendMessageTimeoutA (USER32.@)
1929 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1930 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1932 struct send_message_info info;
1933 DWORD dest_tid, dest_pid;
1934 LRESULT ret, result;
1936 info.type = MSG_ASCII;
1939 info.wparam = wparam;
1940 info.lparam = lparam;
1942 info.timeout = timeout;
1944 if (is_broadcast(hwnd))
1946 EnumWindows( broadcast_message_callback, (LPARAM)&info );
1947 if (res_ptr) *res_ptr = 1;
1951 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
1953 if (USER_IsExitingThread( dest_tid )) return 0;
1955 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
1957 if (dest_tid == GetCurrentThreadId())
1959 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
1962 else if (dest_pid == GetCurrentProcessId())
1964 ret = send_inter_thread_message( dest_tid, &info, &result );
1968 /* inter-process message: need to map to Unicode */
1969 info.type = MSG_OTHER_PROCESS;
1970 if (is_unicode_message( info.msg ))
1972 if (WINPROC_MapMsg32ATo32W( info.hwnd, info.msg, &info.wparam, &info.lparam ) == -1)
1974 ret = send_inter_thread_message( dest_tid, &info, &result );
1975 result = WINPROC_UnmapMsg32ATo32W( info.hwnd, info.msg, info.wparam,
1976 info.lparam, result );
1978 else ret = send_inter_thread_message( dest_tid, &info, &result );
1980 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
1981 if (ret && res_ptr) *res_ptr = result;
1986 /***********************************************************************
1987 * SendMessageW (USER32.@)
1989 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1992 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
1997 /***********************************************************************
1998 * SendMessageA (USER32.@)
2000 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2003 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2008 /***********************************************************************
2009 * SendNotifyMessageA (USER32.@)
2011 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2013 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2017 /***********************************************************************
2018 * SendNotifyMessageW (USER32.@)
2020 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2022 struct send_message_info info;
2026 if (is_pointer_message(msg))
2028 SetLastError(ERROR_INVALID_PARAMETER);
2032 info.type = MSG_NOTIFY;
2035 info.wparam = wparam;
2036 info.lparam = lparam;
2039 if (is_broadcast(hwnd))
2041 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2045 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2047 if (USER_IsExitingThread( dest_tid )) return TRUE;
2049 if (dest_tid == GetCurrentThreadId())
2051 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2054 return send_inter_thread_message( dest_tid, &info, &result );
2058 /***********************************************************************
2059 * SendMessageCallbackA (USER32.@)
2061 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2062 SENDASYNCPROC callback, ULONG_PTR data )
2064 return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
2065 lparam, callback, data );
2069 /***********************************************************************
2070 * SendMessageCallbackW (USER32.@)
2072 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2073 SENDASYNCPROC callback, ULONG_PTR data )
2075 struct send_message_info info;
2079 if (is_pointer_message(msg))
2081 SetLastError(ERROR_INVALID_PARAMETER);
2085 info.type = MSG_CALLBACK;
2088 info.wparam = wparam;
2089 info.lparam = lparam;
2090 info.callback = callback;
2094 if (is_broadcast(hwnd))
2096 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2100 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2102 if (USER_IsExitingThread( dest_tid )) return TRUE;
2104 if (dest_tid == GetCurrentThreadId())
2106 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2107 call_sendmsg_callback( callback, hwnd, msg, data, result );
2110 FIXME( "callback will not be called\n" );
2111 return send_inter_thread_message( dest_tid, &info, &result );
2115 /***********************************************************************
2116 * ReplyMessage (USER32.@)
2118 BOOL WINAPI ReplyMessage( LRESULT result )
2120 MESSAGEQUEUE *queue = QUEUE_Current();
2121 struct received_message_info *info = queue->receive_info;
2123 if (!info) return FALSE;
2124 reply_message( info, result, FALSE );
2129 /***********************************************************************
2130 * InSendMessage (USER32.@)
2132 BOOL WINAPI InSendMessage(void)
2134 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2138 /***********************************************************************
2139 * InSendMessageEx (USER32.@)
2141 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2143 MESSAGEQUEUE *queue = QUEUE_Current();
2144 struct received_message_info *info = queue->receive_info;
2146 if (info) return info->flags;
2147 return ISMEX_NOSEND;
2151 /***********************************************************************
2152 * PostMessageA (USER32.@)
2154 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2156 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2160 /***********************************************************************
2161 * PostMessageW (USER32.@)
2163 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2165 struct send_message_info info;
2168 if (is_pointer_message( msg ))
2170 SetLastError( ERROR_INVALID_PARAMETER );
2174 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2175 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2177 info.type = MSG_POSTED;
2180 info.wparam = wparam;
2181 info.lparam = lparam;
2184 if (is_broadcast(hwnd))
2186 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2190 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2192 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2194 if (USER_IsExitingThread( dest_tid )) return TRUE;
2196 return put_message_in_queue( dest_tid, &info, NULL );
2200 /**********************************************************************
2201 * PostThreadMessageA (USER32.@)
2203 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2205 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2209 /**********************************************************************
2210 * PostThreadMessageW (USER32.@)
2212 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2214 struct send_message_info info;
2216 if (is_pointer_message( msg ))
2218 SetLastError( ERROR_INVALID_PARAMETER );
2221 if (USER_IsExitingThread( thread )) return TRUE;
2223 info.type = MSG_POSTED;
2226 info.wparam = wparam;
2227 info.lparam = lparam;
2229 return put_message_in_queue( thread, &info, NULL );
2233 /***********************************************************************
2234 * PostQuitMessage (USER32.@)
2236 void WINAPI PostQuitMessage( INT exitCode )
2238 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT, exitCode, 0 );
2242 /***********************************************************************
2243 * PeekMessageW (USER32.@)
2245 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2247 MESSAGEQUEUE *queue;
2251 /* check for graphics events */
2252 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2253 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
2255 hwnd = WIN_GetFullHandle( hwnd );
2256 locks = WIN_SuspendWndsLock();
2258 if (!MSG_peek_message( &msg, hwnd, first, last,
2259 (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2261 if (!(flags & PM_NOYIELD))
2264 ReleaseThunkLock(&count);
2265 if (count) RestoreThunkLock(count);
2267 WIN_RestoreWndsLock( locks );
2271 WIN_RestoreWndsLock( locks );
2273 /* need to fill the window handle for WM_PAINT message */
2274 if (msg.message == WM_PAINT)
2276 if (IsIconic( msg.hwnd ) && GetClassLongA( msg.hwnd, GCL_HICON ))
2278 msg.message = WM_PAINTICON;
2281 /* clear internal paint flag */
2282 RedrawWindow( msg.hwnd, NULL, 0, RDW_NOINTERNALPAINT | RDW_NOCHILDREN );
2285 if ((queue = QUEUE_Current()))
2287 queue->GetMessageTimeVal = msg.time;
2288 msg.pt.x = LOWORD( queue->GetMessagePosVal );
2289 msg.pt.y = HIWORD( queue->GetMessagePosVal );
2292 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2294 /* copy back our internal safe copy of message data to msg_out.
2295 * msg_out is a variable from the *program*, so it can't be used
2296 * internally as it can get "corrupted" by our use of SendMessage()
2297 * (back to the program) inside the message handling itself. */
2303 /***********************************************************************
2304 * PeekMessageA (USER32.@)
2306 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2308 BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
2309 if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2314 /***********************************************************************
2315 * GetMessageW (USER32.@)
2317 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2319 MESSAGEQUEUE *queue = QUEUE_Current();
2322 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2325 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2326 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2327 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2328 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2329 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2330 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2332 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
2334 locks = WIN_SuspendWndsLock();
2336 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
2338 /* wait until one of the bits is set */
2339 unsigned int wake_bits = 0, changed_bits = 0;
2342 SERVER_START_REQ( set_queue_mask )
2344 req->wake_mask = QS_SENDMESSAGE;
2345 req->changed_mask = mask;
2347 if (!wine_server_call( req ))
2349 wake_bits = reply->wake_bits;
2350 changed_bits = reply->changed_bits;
2355 if (changed_bits & mask) continue;
2356 if (wake_bits & QS_SENDMESSAGE) continue;
2358 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2359 queue->self, mask, wake_bits, changed_bits );
2361 ReleaseThunkLock( &dwlc );
2362 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2363 USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue, INFINITE, 0, 0 );
2365 WaitForSingleObject( queue->server_queue, INFINITE );
2366 if (dwlc) RestoreThunkLock( dwlc );
2369 WIN_RestoreWndsLock( locks );
2371 return (msg->message != WM_QUIT);
2375 /***********************************************************************
2376 * GetMessageA (USER32.@)
2378 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2380 GetMessageW( msg, hwnd, first, last );
2381 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2382 return (msg->message != WM_QUIT);
2386 /***********************************************************************
2387 * IsDialogMessage (USER32.@)
2388 * IsDialogMessageA (USER32.@)
2390 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2393 msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
2394 return IsDialogMessageW( hwndDlg, &msg );
2398 /***********************************************************************
2399 * SetMessageQueue (USER32.@)
2401 BOOL WINAPI SetMessageQueue( INT size )
2403 /* now obsolete the message queue will be expanded dynamically as necessary */
2408 /**********************************************************************
2409 * AttachThreadInput (USER32.@)
2411 * Attaches the input processing mechanism of one thread to that of
2414 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
2418 SERVER_START_REQ( attach_thread_input )
2420 req->tid_from = from;
2422 req->attach = attach;
2423 ret = !wine_server_call_err( req );
2430 /**********************************************************************
2431 * GetGUIThreadInfo (USER32.@)
2433 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
2437 SERVER_START_REQ( get_thread_input )
2440 if ((ret = !wine_server_call_err( req )))
2443 info->hwndActive = reply->active;
2444 info->hwndFocus = reply->focus;
2445 info->hwndCapture = reply->capture;
2446 info->hwndMenuOwner = reply->menu_owner;
2447 info->hwndMoveSize = reply->move_size;
2448 info->hwndCaret = reply->caret;
2449 info->rcCaret.left = reply->rect.left;
2450 info->rcCaret.top = reply->rect.top;
2451 info->rcCaret.right = reply->rect.right;
2452 info->rcCaret.bottom = reply->rect.bottom;
2453 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
2454 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
2455 if (reply->caret) info->flags |= GUI_CARETBLINKING;
2463 /**********************************************************************
2464 * GetKeyState (USER32.@)
2466 * An application calls the GetKeyState function in response to a
2467 * keyboard-input message. This function retrieves the state of the key
2468 * at the time the input message was generated.
2470 SHORT WINAPI GetKeyState(INT vkey)
2474 SERVER_START_REQ( get_key_state )
2476 req->tid = GetCurrentThreadId();
2478 if (!wine_server_call( req )) retval = (signed char)reply->state;
2481 TRACE("key (0x%x) -> %x\n", vkey, retval);
2486 /**********************************************************************
2487 * GetKeyboardState (USER32.@)
2489 BOOL WINAPI GetKeyboardState( LPBYTE state )
2493 TRACE("(%p)\n", state);
2495 memset( state, 0, 256 );
2496 SERVER_START_REQ( get_key_state )
2498 req->tid = GetCurrentThreadId();
2500 wine_server_set_reply( req, state, 256 );
2501 ret = !wine_server_call_err( req );
2508 /**********************************************************************
2509 * SetKeyboardState (USER32.@)
2511 BOOL WINAPI SetKeyboardState( LPBYTE state )
2515 TRACE("(%p)\n", state);
2517 SERVER_START_REQ( set_key_state )
2519 req->tid = GetCurrentThreadId();
2520 wine_server_add_data( req, state, 256 );
2521 ret = !wine_server_call_err( req );
2527 /******************************************************************
2528 * IsHungAppWindow (USER32.@)
2531 BOOL WINAPI IsHungAppWindow( HWND hWnd )
2534 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);