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 = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1164 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1167 LeaveCriticalSection(&dde_crst);
1171 /* zero out newly allocated part */
1172 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1173 dde_num_alloc += GROWBY;
1176 for (i = 0; i < dde_num_alloc; i++)
1178 if (dde_pairs[i].server_hMem == 0)
1180 dde_pairs[i].client_hMem = chm;
1181 dde_pairs[i].server_hMem = shm;
1186 LeaveCriticalSection(&dde_crst);
1190 static HGLOBAL dde_get_pair(HGLOBAL shm)
1195 EnterCriticalSection(&dde_crst);
1196 for (i = 0; i < dde_num_alloc; i++)
1198 if (dde_pairs[i].server_hMem == shm)
1200 /* free this pair */
1201 dde_pairs[i].server_hMem = 0;
1203 ret = dde_pairs[i].client_hMem;
1207 LeaveCriticalSection(&dde_crst);
1211 /***********************************************************************
1214 * Post a DDE message
1216 static BOOL post_dde_message( DWORD dest_tid, struct packed_message *data, const struct send_message_info *info )
1222 HGLOBAL hunlock = 0;
1226 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1232 /* DDE messages which don't require packing are:
1241 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1242 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1245 /* send back the value of h on the other side */
1246 push_data( data, &h, sizeof(HGLOBAL) );
1248 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo, uiHi, (DWORD)h );
1253 /* uiHi should contain either an atom or 0 */
1254 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1255 lp = MAKELONG( uiLo, uiHi );
1264 size = GlobalSize( (HGLOBAL)uiLo ) ;
1265 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1266 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1267 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1271 else if (info->msg != WM_DDE_DATA) return FALSE;
1276 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1278 DDEDATA *dde_data = (DDEDATA *)ptr;
1279 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1280 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1281 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1282 push_data( data, ptr, size );
1283 hunlock = (HGLOBAL)uiLo;
1286 TRACE( "send ddepack %u %x\n", size, uiHi );
1288 case WM_DDE_EXECUTE:
1291 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1293 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1294 /* so that the other side can send it back on ACK */
1296 hunlock = (HGLOBAL)info->lparam;
1301 SERVER_START_REQ( send_message )
1304 req->type = info->type;
1306 req->win = info->hwnd;
1307 req->msg = info->msg;
1308 req->wparam = info->wparam;
1310 req->time = GetCurrentTime();
1312 for (i = 0; i < data->count; i++)
1313 wine_server_add_data( req, data->data[i], data->size[i] );
1314 if ((res = wine_server_call( req )))
1316 if (res == STATUS_INVALID_PARAMETER)
1317 /* FIXME: find a STATUS_ value for this one */
1318 SetLastError( ERROR_INVALID_THREAD_ID );
1320 SetLastError( RtlNtStatusToDosError(res) );
1323 FreeDDElParam(info->msg, info->lparam);
1326 if (hunlock) GlobalUnlock(hunlock);
1331 /***********************************************************************
1332 * unpack_dde_message
1334 * Unpack a posted DDE message received from another process.
1336 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1337 void **buffer, size_t size )
1348 /* hMem is being passed */
1349 if (size != sizeof(HGLOBAL)) return FALSE;
1350 if (!buffer || !*buffer) return FALSE;
1352 memcpy( &hMem, *buffer, size );
1354 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1358 uiLo = LOWORD( *lparam );
1359 uiHi = HIWORD( *lparam );
1360 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1362 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1367 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1369 TRACE( "recv ddepack %u %x\n", size, uiHi );
1372 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1373 if (hMem && (ptr = GlobalLock( hMem )))
1375 memcpy( ptr, *buffer, size );
1376 GlobalUnlock( hMem );
1382 *lparam = PackDDElParam( message, uiLo, uiHi );
1384 case WM_DDE_EXECUTE:
1387 if (!buffer || !*buffer) return FALSE;
1388 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1389 if (hMem && (ptr = GlobalLock( hMem )))
1391 memcpy( ptr, *buffer, size );
1392 GlobalUnlock( hMem );
1393 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1394 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1400 } else return FALSE;
1401 *lparam = (LPARAM)hMem;
1407 /***********************************************************************
1410 * Call a window procedure and the corresponding hooks.
1412 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1413 BOOL unicode, BOOL same_thread )
1418 CWPRETSTRUCT cwpret;
1419 MESSAGEQUEUE *queue = QUEUE_Current();
1421 if (queue->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1422 queue->recursion_count++;
1424 if (msg & 0x80000000)
1426 result = handle_internal_message( hwnd, msg, wparam, lparam );
1430 /* first the WH_CALLWNDPROC hook */
1431 hwnd = WIN_GetFullHandle( hwnd );
1432 cwp.lParam = lparam;
1433 cwp.wParam = wparam;
1436 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1438 /* now call the window procedure */
1441 if (!(winproc = (WNDPROC)GetWindowLongW( hwnd, GWL_WNDPROC ))) goto done;
1442 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1446 if (!(winproc = (WNDPROC)GetWindowLongA( hwnd, GWL_WNDPROC ))) goto done;
1447 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1450 /* and finally the WH_CALLWNDPROCRET hook */
1451 cwpret.lResult = result;
1452 cwpret.lParam = lparam;
1453 cwpret.wParam = wparam;
1454 cwpret.message = msg;
1456 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1458 queue->recursion_count--;
1463 /***********************************************************************
1464 * process_hardware_message
1466 * Process a hardware message; return TRUE if message should be passed on to the app
1468 static BOOL process_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd,
1469 UINT first, UINT last, BOOL remove )
1473 if (!MSG_process_raw_hardware_message( msg, extra_info, hwnd, first, last, remove ))
1476 ret = MSG_process_cooked_hardware_message( msg, extra_info, remove );
1478 /* tell the server we have passed it to the app
1479 * (even though we may end up dropping it later on)
1481 SERVER_START_REQ( reply_message )
1483 req->type = MSG_HARDWARE;
1485 req->remove = remove || !ret;
1486 wine_server_call( req );
1493 /***********************************************************************
1494 * call_sendmsg_callback
1496 * Call the callback function of SendMessageCallback.
1498 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1499 ULONG_PTR data, LRESULT result )
1501 if (TRACE_ON(relay))
1502 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1503 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1505 callback( hwnd, msg, data, result );
1506 if (TRACE_ON(relay))
1507 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1508 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1513 /***********************************************************************
1516 * Peek for a message matching the given parameters. Return FALSE if none available.
1517 * All pending sent messages are processed before returning.
1519 BOOL MSG_peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1522 ULONG_PTR extra_info = 0;
1523 MESSAGEQUEUE *queue = QUEUE_Current();
1524 struct received_message_info info, *old_info;
1526 if (!first && !last) last = ~0;
1531 void *buffer = NULL;
1532 size_t size = 0, buffer_size = 0;
1534 do /* loop while buffer is too small */
1536 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1538 SERVER_START_REQ( get_message )
1541 req->get_win = hwnd;
1542 req->get_first = first;
1543 req->get_last = last;
1544 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1545 if (!(res = wine_server_call( req )))
1547 size = wine_server_reply_size( reply );
1548 info.type = reply->type;
1549 info.msg.hwnd = reply->win;
1550 info.msg.message = reply->msg;
1551 info.msg.wParam = reply->wparam;
1552 info.msg.lParam = reply->lparam;
1553 info.msg.time = reply->time;
1554 info.msg.pt.x = reply->x;
1555 info.msg.pt.y = reply->y;
1556 extra_info = reply->info;
1560 if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
1561 buffer_size = reply->total;
1565 } while (res == STATUS_BUFFER_OVERFLOW);
1567 if (res) return FALSE;
1569 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1570 info.type, info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1571 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1577 info.flags = ISMEX_SEND;
1580 info.flags = ISMEX_NOTIFY;
1583 info.flags = ISMEX_CALLBACK;
1585 case MSG_CALLBACK_RESULT:
1586 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
1587 info.msg.message, extra_info, info.msg.lParam );
1589 case MSG_OTHER_PROCESS:
1590 info.flags = ISMEX_SEND;
1591 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1592 &info.msg.lParam, &buffer, size ))
1594 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1595 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
1596 info.msg.wParam, info.msg.lParam, size );
1598 reply_message( &info, 0, TRUE );
1603 if (!process_hardware_message( &info.msg, extra_info,
1604 hwnd, first, last, flags & GET_MSG_REMOVE ))
1606 TRACE("dropping msg %x\n", info.msg.message );
1607 goto next; /* ignore it */
1609 queue->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
1612 queue->GetMessageExtraInfoVal = extra_info;
1613 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
1615 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1616 &info.msg.lParam, &buffer, size ))
1618 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1619 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1620 info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
1621 goto next; /* ignore it */
1625 if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
1629 /* if we get here, we have a sent message; call the window procedure */
1630 old_info = queue->receive_info;
1631 queue->receive_info = &info;
1632 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
1633 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
1634 reply_message( &info, result, TRUE );
1635 queue->receive_info = old_info;
1637 if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
1642 /***********************************************************************
1643 * wait_message_reply
1645 * Wait until a sent message gets replied to.
1647 static void wait_message_reply( UINT flags )
1649 MESSAGEQUEUE *queue;
1651 if (!(queue = QUEUE_Current())) return;
1655 unsigned int wake_bits = 0, changed_bits = 0;
1658 SERVER_START_REQ( set_queue_mask )
1660 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
1661 req->changed_mask = req->wake_mask;
1663 if (!wine_server_call( req ))
1665 wake_bits = reply->wake_bits;
1666 changed_bits = reply->changed_bits;
1671 if (wake_bits & QS_SMRESULT) return; /* got a result */
1672 if (wake_bits & QS_SENDMESSAGE)
1674 /* Process the sent message immediately */
1676 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
1680 /* now wait for it */
1682 ReleaseThunkLock( &dwlc );
1684 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
1685 res = USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue,
1688 res = WaitForSingleObject( queue->server_queue, INFINITE );
1690 if (dwlc) RestoreThunkLock( dwlc );
1694 /***********************************************************************
1695 * put_message_in_queue
1697 * Put a sent message into the destination queue.
1698 * For inter-process message, reply_size is set to expected size of reply data.
1700 static BOOL put_message_in_queue( DWORD dest_tid, const struct send_message_info *info,
1701 size_t *reply_size )
1703 struct packed_message data;
1705 int i, timeout = -1;
1707 if (info->type != MSG_NOTIFY &&
1708 info->type != MSG_CALLBACK &&
1709 info->type != MSG_POSTED &&
1710 info->timeout != INFINITE)
1711 timeout = info->timeout;
1714 if (info->type == MSG_OTHER_PROCESS)
1716 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
1717 if (data.count == -1)
1719 WARN( "cannot pack message %x\n", info->msg );
1723 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
1725 return post_dde_message( dest_tid, &data, info );
1728 SERVER_START_REQ( send_message )
1731 req->type = info->type;
1733 req->win = info->hwnd;
1734 req->msg = info->msg;
1735 req->wparam = info->wparam;
1736 req->lparam = info->lparam;
1737 req->time = GetCurrentTime();
1738 req->timeout = timeout;
1740 if (info->type == MSG_CALLBACK)
1742 req->callback = info->callback;
1743 req->info = info->data;
1746 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
1747 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1748 if ((res = wine_server_call( req )))
1750 if (res == STATUS_INVALID_PARAMETER)
1751 /* FIXME: find a STATUS_ value for this one */
1752 SetLastError( ERROR_INVALID_THREAD_ID );
1754 SetLastError( RtlNtStatusToDosError(res) );
1762 /***********************************************************************
1765 * Retrieve a message reply from the server.
1767 static LRESULT retrieve_reply( const struct send_message_info *info,
1768 size_t reply_size, LRESULT *result )
1771 void *reply_data = NULL;
1775 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
1777 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
1781 SERVER_START_REQ( get_message_reply )
1784 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
1785 if (!(status = wine_server_call( req ))) *result = reply->result;
1786 reply_size = wine_server_reply_size( reply );
1789 if (!status && reply_size)
1790 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
1792 if (reply_data) HeapFree( GetProcessHeap(), 0, reply_data );
1794 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1795 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
1796 info->lparam, *result, status );
1798 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
1799 if (status) SetLastError( RtlNtStatusToDosError(status) );
1804 /***********************************************************************
1805 * send_inter_thread_message
1807 static LRESULT send_inter_thread_message( DWORD dest_tid, const struct send_message_info *info,
1812 size_t reply_size = 0;
1814 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
1815 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
1817 if (!put_message_in_queue( dest_tid, info, &reply_size )) return 0;
1819 /* there's no reply to wait for on notify/callback messages */
1820 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
1822 locks = WIN_SuspendWndsLock();
1824 wait_message_reply( info->flags );
1825 ret = retrieve_reply( info, reply_size, res_ptr );
1827 WIN_RestoreWndsLock( locks );
1832 /***********************************************************************
1833 * MSG_SendInternalMessageTimeout
1835 * Same as SendMessageTimeoutW but sends the message to a specific thread
1836 * without requiring a window handle. Only works for internal Wine messages.
1838 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
1839 UINT msg, WPARAM wparam, LPARAM lparam,
1840 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1842 struct send_message_info info;
1843 LRESULT ret, result;
1845 assert( msg & 0x80000000 ); /* must be an internal Wine message */
1847 info.type = MSG_UNICODE;
1850 info.wparam = wparam;
1851 info.lparam = lparam;
1853 info.timeout = timeout;
1855 if (USER_IsExitingThread( dest_tid )) return 0;
1857 if (dest_tid == GetCurrentThreadId())
1859 result = handle_internal_message( 0, msg, wparam, lparam );
1864 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1865 ret = send_inter_thread_message( dest_tid, &info, &result );
1867 if (ret && res_ptr) *res_ptr = result;
1872 /***********************************************************************
1873 * SendMessageTimeoutW (USER32.@)
1875 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1876 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1878 struct send_message_info info;
1879 DWORD dest_tid, dest_pid;
1880 LRESULT ret, result;
1882 info.type = MSG_UNICODE;
1885 info.wparam = wparam;
1886 info.lparam = lparam;
1888 info.timeout = timeout;
1890 if (is_broadcast(hwnd))
1892 EnumWindows( broadcast_message_callback, (LPARAM)&info );
1893 if (res_ptr) *res_ptr = 1;
1897 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
1899 if (USER_IsExitingThread( dest_tid )) return 0;
1901 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
1903 if (dest_tid == GetCurrentThreadId())
1905 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
1910 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1911 ret = send_inter_thread_message( dest_tid, &info, &result );
1914 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
1915 if (ret && res_ptr) *res_ptr = result;
1920 /***********************************************************************
1921 * SendMessageTimeoutA (USER32.@)
1923 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1924 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1926 struct send_message_info info;
1927 DWORD dest_tid, dest_pid;
1928 LRESULT ret, result;
1930 info.type = MSG_ASCII;
1933 info.wparam = wparam;
1934 info.lparam = lparam;
1936 info.timeout = timeout;
1938 if (is_broadcast(hwnd))
1940 EnumWindows( broadcast_message_callback, (LPARAM)&info );
1941 if (res_ptr) *res_ptr = 1;
1945 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
1947 if (USER_IsExitingThread( dest_tid )) return 0;
1949 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
1951 if (dest_tid == GetCurrentThreadId())
1953 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
1956 else if (dest_pid == GetCurrentProcessId())
1958 ret = send_inter_thread_message( dest_tid, &info, &result );
1962 /* inter-process message: need to map to Unicode */
1963 info.type = MSG_OTHER_PROCESS;
1964 if (is_unicode_message( info.msg ))
1966 if (WINPROC_MapMsg32ATo32W( info.hwnd, info.msg, &info.wparam, &info.lparam ) == -1)
1968 ret = send_inter_thread_message( dest_tid, &info, &result );
1969 result = WINPROC_UnmapMsg32ATo32W( info.hwnd, info.msg, info.wparam,
1970 info.lparam, result );
1972 else ret = send_inter_thread_message( dest_tid, &info, &result );
1974 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
1975 if (ret && res_ptr) *res_ptr = result;
1980 /***********************************************************************
1981 * SendMessageW (USER32.@)
1983 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1986 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
1991 /***********************************************************************
1992 * SendMessageA (USER32.@)
1994 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1997 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2002 /***********************************************************************
2003 * SendNotifyMessageA (USER32.@)
2005 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2007 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2011 /***********************************************************************
2012 * SendNotifyMessageW (USER32.@)
2014 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2016 struct send_message_info info;
2020 if (is_pointer_message(msg))
2022 SetLastError(ERROR_INVALID_PARAMETER);
2026 info.type = MSG_NOTIFY;
2029 info.wparam = wparam;
2030 info.lparam = lparam;
2033 if (is_broadcast(hwnd))
2035 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2039 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2041 if (USER_IsExitingThread( dest_tid )) return TRUE;
2043 if (dest_tid == GetCurrentThreadId())
2045 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2048 return send_inter_thread_message( dest_tid, &info, &result );
2052 /***********************************************************************
2053 * SendMessageCallbackA (USER32.@)
2055 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2056 SENDASYNCPROC callback, ULONG_PTR data )
2058 return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
2059 lparam, callback, data );
2063 /***********************************************************************
2064 * SendMessageCallbackW (USER32.@)
2066 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2067 SENDASYNCPROC callback, ULONG_PTR data )
2069 struct send_message_info info;
2073 if (is_pointer_message(msg))
2075 SetLastError(ERROR_INVALID_PARAMETER);
2079 info.type = MSG_CALLBACK;
2082 info.wparam = wparam;
2083 info.lparam = lparam;
2084 info.callback = callback;
2088 if (is_broadcast(hwnd))
2090 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2094 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2096 if (USER_IsExitingThread( dest_tid )) return TRUE;
2098 if (dest_tid == GetCurrentThreadId())
2100 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2101 call_sendmsg_callback( callback, hwnd, msg, data, result );
2104 FIXME( "callback will not be called\n" );
2105 return send_inter_thread_message( dest_tid, &info, &result );
2109 /***********************************************************************
2110 * ReplyMessage (USER32.@)
2112 BOOL WINAPI ReplyMessage( LRESULT result )
2114 MESSAGEQUEUE *queue = QUEUE_Current();
2115 struct received_message_info *info = queue->receive_info;
2117 if (!info) return FALSE;
2118 reply_message( info, result, FALSE );
2123 /***********************************************************************
2124 * InSendMessage (USER32.@)
2126 BOOL WINAPI InSendMessage(void)
2128 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2132 /***********************************************************************
2133 * InSendMessageEx (USER32.@)
2135 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2137 MESSAGEQUEUE *queue = QUEUE_Current();
2138 struct received_message_info *info = queue->receive_info;
2140 if (info) return info->flags;
2141 return ISMEX_NOSEND;
2145 /***********************************************************************
2146 * PostMessageA (USER32.@)
2148 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2150 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2154 /***********************************************************************
2155 * PostMessageW (USER32.@)
2157 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2159 struct send_message_info info;
2162 if (is_pointer_message( msg ))
2164 SetLastError( ERROR_INVALID_PARAMETER );
2168 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2169 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2171 info.type = MSG_POSTED;
2174 info.wparam = wparam;
2175 info.lparam = lparam;
2178 if (is_broadcast(hwnd))
2180 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2184 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2186 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2188 if (USER_IsExitingThread( dest_tid )) return TRUE;
2190 return put_message_in_queue( dest_tid, &info, NULL );
2194 /**********************************************************************
2195 * PostThreadMessageA (USER32.@)
2197 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2199 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2203 /**********************************************************************
2204 * PostThreadMessageW (USER32.@)
2206 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2208 struct send_message_info info;
2210 if (is_pointer_message( msg ))
2212 SetLastError( ERROR_INVALID_PARAMETER );
2215 if (USER_IsExitingThread( thread )) return TRUE;
2217 info.type = MSG_POSTED;
2220 info.wparam = wparam;
2221 info.lparam = lparam;
2223 return put_message_in_queue( thread, &info, NULL );
2227 /***********************************************************************
2228 * PostQuitMessage (USER32.@)
2230 void WINAPI PostQuitMessage( INT exitCode )
2232 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT, exitCode, 0 );
2236 /***********************************************************************
2237 * PeekMessageW (USER32.@)
2239 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2241 MESSAGEQUEUE *queue;
2245 /* check for graphics events */
2246 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2247 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
2249 hwnd = WIN_GetFullHandle( hwnd );
2250 locks = WIN_SuspendWndsLock();
2252 if (!MSG_peek_message( &msg, hwnd, first, last,
2253 (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2255 if (!(flags & PM_NOYIELD))
2258 ReleaseThunkLock(&count);
2259 if (count) RestoreThunkLock(count);
2261 WIN_RestoreWndsLock( locks );
2265 WIN_RestoreWndsLock( locks );
2267 /* need to fill the window handle for WM_PAINT message */
2268 if (msg.message == WM_PAINT)
2270 if (IsIconic( msg.hwnd ) && GetClassLongA( msg.hwnd, GCL_HICON ))
2272 msg.message = WM_PAINTICON;
2275 /* clear internal paint flag */
2276 RedrawWindow( msg.hwnd, NULL, 0, RDW_NOINTERNALPAINT | RDW_NOCHILDREN );
2279 if ((queue = QUEUE_Current()))
2281 queue->GetMessageTimeVal = msg.time;
2282 msg.pt.x = LOWORD( queue->GetMessagePosVal );
2283 msg.pt.y = HIWORD( queue->GetMessagePosVal );
2286 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2288 /* copy back our internal safe copy of message data to msg_out.
2289 * msg_out is a variable from the *program*, so it can't be used
2290 * internally as it can get "corrupted" by our use of SendMessage()
2291 * (back to the program) inside the message handling itself. */
2297 /***********************************************************************
2298 * PeekMessageA (USER32.@)
2300 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2302 BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
2303 if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2308 /***********************************************************************
2309 * GetMessageW (USER32.@)
2311 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2313 MESSAGEQUEUE *queue = QUEUE_Current();
2316 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2319 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2320 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2321 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2322 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2323 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2324 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2326 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
2328 locks = WIN_SuspendWndsLock();
2330 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
2332 /* wait until one of the bits is set */
2333 unsigned int wake_bits = 0, changed_bits = 0;
2336 SERVER_START_REQ( set_queue_mask )
2338 req->wake_mask = QS_SENDMESSAGE;
2339 req->changed_mask = mask;
2341 if (!wine_server_call( req ))
2343 wake_bits = reply->wake_bits;
2344 changed_bits = reply->changed_bits;
2349 if (changed_bits & mask) continue;
2350 if (wake_bits & QS_SENDMESSAGE) continue;
2352 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2353 queue->self, mask, wake_bits, changed_bits );
2355 ReleaseThunkLock( &dwlc );
2356 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2357 USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue, INFINITE, 0, 0 );
2359 WaitForSingleObject( queue->server_queue, INFINITE );
2360 if (dwlc) RestoreThunkLock( dwlc );
2363 WIN_RestoreWndsLock( locks );
2365 return (msg->message != WM_QUIT);
2369 /***********************************************************************
2370 * GetMessageA (USER32.@)
2372 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2374 GetMessageW( msg, hwnd, first, last );
2375 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2376 return (msg->message != WM_QUIT);
2380 /***********************************************************************
2381 * IsDialogMessage (USER32.@)
2382 * IsDialogMessageA (USER32.@)
2384 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2387 msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
2388 return IsDialogMessageW( hwndDlg, &msg );
2392 /***********************************************************************
2393 * SetMessageQueue (USER32.@)
2395 BOOL WINAPI SetMessageQueue( INT size )
2397 /* now obsolete the message queue will be expanded dynamically as necessary */
2402 /**********************************************************************
2403 * AttachThreadInput (USER32.@)
2405 * Attaches the input processing mechanism of one thread to that of
2408 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
2412 SERVER_START_REQ( attach_thread_input )
2414 req->tid_from = from;
2416 req->attach = attach;
2417 ret = !wine_server_call_err( req );
2424 /**********************************************************************
2425 * GetGUIThreadInfo (USER32.@)
2427 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
2431 SERVER_START_REQ( get_thread_input )
2434 if ((ret = !wine_server_call_err( req )))
2437 info->hwndActive = reply->active;
2438 info->hwndFocus = reply->focus;
2439 info->hwndCapture = reply->capture;
2440 info->hwndMenuOwner = reply->menu_owner;
2441 info->hwndMoveSize = reply->move_size;
2442 info->hwndCaret = reply->caret;
2443 info->rcCaret.left = reply->rect.left;
2444 info->rcCaret.top = reply->rect.top;
2445 info->rcCaret.right = reply->rect.right;
2446 info->rcCaret.bottom = reply->rect.bottom;
2447 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
2448 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
2449 if (reply->caret) info->flags |= GUI_CARETBLINKING;
2457 /**********************************************************************
2458 * GetKeyState (USER32.@)
2460 * An application calls the GetKeyState function in response to a
2461 * keyboard-input message. This function retrieves the state of the key
2462 * at the time the input message was generated.
2464 SHORT WINAPI GetKeyState(INT vkey)
2468 SERVER_START_REQ( get_key_state )
2470 req->tid = GetCurrentThreadId();
2472 if (!wine_server_call( req )) retval = (signed char)reply->state;
2475 TRACE("key (0x%x) -> %x\n", vkey, retval);
2480 /**********************************************************************
2481 * GetKeyboardState (USER32.@)
2483 BOOL WINAPI GetKeyboardState( LPBYTE state )
2487 TRACE("(%p)\n", state);
2489 memset( state, 0, 256 );
2490 SERVER_START_REQ( get_key_state )
2492 req->tid = GetCurrentThreadId();
2494 wine_server_set_reply( req, state, 256 );
2495 ret = !wine_server_call_err( req );
2502 /**********************************************************************
2503 * SetKeyboardState (USER32.@)
2505 BOOL WINAPI SetKeyboardState( LPBYTE state )
2509 TRACE("(%p)\n", state);
2511 SERVER_START_REQ( set_key_state )
2513 req->tid = GetCurrentThreadId();
2514 wine_server_add_data( req, state, 256 );
2515 ret = !wine_server_call_err( req );
2521 /******************************************************************
2522 * IsHungAppWindow (USER32.@)
2525 BOOL WINAPI IsHungAppWindow( HWND hWnd )
2528 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);