2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
13 #include "wine/winbase16.h"
14 #include "wine/winuser16.h"
31 #include "debugtools.h"
33 DEFAULT_DEBUG_CHANNEL(msg);
34 DECLARE_DEBUG_CHANNEL(key);
36 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
37 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
43 static UINT doubleClickSpeed = 452;
45 static BOOL MSG_ConvertMsg( MSG *msg, int srcType, int dstType );
49 /* flag for messages that contain pointers */
50 /* 16 messages per entry, messages 0..15 map to bits 0..15 */
52 #define SET(msg) (1 << ((msg) & 15))
54 static const unsigned short message_pointer_flags[] =
57 SET(WM_CREATE) | SET(WM_GETTEXT) | SET(WM_SETTEXT),
61 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM),
65 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) | SET(WM_NOTIFY),
71 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
73 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
79 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
81 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
97 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_INSERTSTRING) |
98 SET(CB_FINDSTRING) | SET(CB_SELECTSTRING),
100 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
106 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
107 SET(LB_DIR) | SET(LB_FINDSTRING),
109 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
111 SET(LB_FINDSTRINGEXACT),
127 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
128 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE)
133 /***********************************************************************
136 inline static int is_pointer_message( UINT message )
138 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
139 return (message_pointer_flags[message / 16] & (1 << (message & 15))) != 0;
143 /***********************************************************************
144 * is_keyboard_message
146 inline static BOOL is_keyboard_message( UINT message )
148 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
152 /***********************************************************************
155 inline static BOOL is_mouse_message( UINT message )
157 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
158 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
162 /***********************************************************************
163 * check_message_filter
165 inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
169 if (msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
173 return (msg->message >= first && msg->message <= last);
179 /***********************************************************************
182 * Convert the wparam of an ASCII message to Unicode.
184 static WPARAM map_wparam_AtoW( UINT message, WPARAM wparam )
186 if (message == WM_CHARTOITEM ||
187 message == EM_SETPASSWORDCHAR ||
188 message == WM_CHAR ||
189 message == WM_DEADCHAR ||
190 message == WM_SYSCHAR ||
191 message == WM_SYSDEADCHAR ||
192 message == WM_MENUCHAR)
194 char ch = LOWORD(wparam);
196 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
197 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
203 /***********************************************************************
206 * Convert the wparam of a Unicode message to ASCII.
208 static WPARAM map_wparam_WtoA( UINT message, WPARAM wparam )
210 if (message == WM_CHARTOITEM ||
211 message == EM_SETPASSWORDCHAR ||
212 message == WM_CHAR ||
213 message == WM_DEADCHAR ||
214 message == WM_SYSCHAR ||
215 message == WM_SYSDEADCHAR ||
216 message == WM_MENUCHAR)
218 WCHAR wch = LOWORD(wparam);
220 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
221 wparam = MAKEWPARAM( ch, HIWORD(wparam) );
227 /***********************************************************************
228 * queue_hardware_message
230 * store a hardware message in the thread queue
232 static void queue_hardware_message( MSG *msg, ULONG_PTR extra_info, enum message_kind kind )
234 SERVER_START_REQ( send_message )
237 req->id = (void *)GetWindowThreadProcessId( msg->hwnd, NULL );
239 req->win = msg->hwnd;
240 req->msg = msg->message;
241 req->wparam = msg->wParam;
242 req->lparam = msg->lParam;
245 req->time = msg->time;
246 req->info = extra_info;
253 /***********************************************************************
254 * MSG_SendParentNotify
256 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
257 * the window has the WS_EX_NOPARENTNOTIFY style.
259 static void MSG_SendParentNotify( HWND hwnd, WORD event, WORD idChild, POINT pt )
261 WND *tmpWnd = WIN_FindWndPtr(hwnd);
263 /* pt has to be in the client coordinates of the parent window */
264 MapWindowPoints( 0, tmpWnd->hwndSelf, &pt, 1 );
267 if (!(tmpWnd->dwStyle & WS_CHILD) || (tmpWnd->dwExStyle & WS_EX_NOPARENTNOTIFY))
269 WIN_ReleaseWndPtr(tmpWnd);
272 pt.x += tmpWnd->rectClient.left;
273 pt.y += tmpWnd->rectClient.top;
274 WIN_UpdateWndPtr(&tmpWnd,tmpWnd->parent);
275 SendMessageA( tmpWnd->hwndSelf, WM_PARENTNOTIFY,
276 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
281 /***********************************************************************
282 * MSG_JournalPlayBackMsg
284 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
286 static void MSG_JournalPlayBackMsg(void)
293 if (!HOOK_IsHooked( WH_JOURNALPLAYBACK )) return;
295 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg );
296 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
300 msg.message = tmpMsg.message;
301 msg.hwnd = tmpMsg.hwnd;
302 msg.time = tmpMsg.time;
303 if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
305 msg.wParam = tmpMsg.paramL & 0xFF;
306 msg.lParam = MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
307 if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
309 for (keyDown=i=0; i<256 && !keyDown; i++)
310 if (InputKeyStateTable[i] & 0x80)
313 msg.lParam |= 0x40000000;
314 AsyncKeyStateTable[msg.wParam]=InputKeyStateTable[msg.wParam] |= 0x80;
316 else /* WM_KEYUP, WM_SYSKEYUP */
318 msg.lParam |= 0xC0000000;
319 AsyncKeyStateTable[msg.wParam]=InputKeyStateTable[msg.wParam] &= ~0x80;
321 if (InputKeyStateTable[VK_MENU] & 0x80)
322 msg.lParam |= 0x20000000;
323 if (tmpMsg.paramH & 0x8000) /*special_key bit*/
324 msg.lParam |= 0x01000000;
326 msg.pt.x = msg.pt.y = 0;
327 queue_hardware_message( &msg, 0, RAW_HW_MESSAGE );
329 else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
331 switch (tmpMsg.message)
334 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
336 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
338 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
340 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
342 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
344 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
346 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
347 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
348 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
349 SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
350 msg.lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
352 if (MouseButtonsStates[0]) msg.wParam |= MK_LBUTTON;
353 if (MouseButtonsStates[1]) msg.wParam |= MK_MBUTTON;
354 if (MouseButtonsStates[2]) msg.wParam |= MK_RBUTTON;
356 msg.pt.x = tmpMsg.paramL;
357 msg.pt.y = tmpMsg.paramH;
358 queue_hardware_message( &msg, 0, RAW_HW_MESSAGE );
360 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg);
364 if( tmpMsg.message == WM_QUEUESYNC )
365 if (HOOK_IsHooked( WH_CBT ))
366 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
371 /***********************************************************************
372 * process_raw_keyboard_message
374 * returns TRUE if the contents of 'msg' should be passed to the application
376 static BOOL process_raw_keyboard_message( MSG *msg, ULONG_PTR extra_info )
378 if (!(msg->hwnd = GetFocus()))
380 /* Send the message to the active window instead, */
381 /* translating messages to their WM_SYS equivalent */
382 msg->hwnd = GetActiveWindow();
383 if (msg->message < WM_SYSKEYDOWN) msg->message += WM_SYSKEYDOWN - WM_KEYDOWN;
386 if (HOOK_IsHooked( WH_JOURNALRECORD ))
390 event.message = msg->message;
391 event.hwnd = msg->hwnd;
392 event.time = msg->time;
393 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
394 event.paramH = msg->lParam & 0x7FFF;
395 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
396 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
399 return (msg->hwnd != 0);
403 /***********************************************************************
404 * process_cooked_keyboard_message
406 * returns TRUE if the contents of 'msg' should be passed to the application
408 static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove )
412 /* Handle F1 key by sending out WM_HELP message */
413 if ((msg->message == WM_KEYUP) &&
414 (msg->wParam == VK_F1) &&
415 (msg->hwnd != GetDesktopWindow()) &&
416 !MENU_IsMenuActive())
419 hi.cbSize = sizeof(HELPINFO);
420 hi.iContextType = HELPINFO_WINDOW;
421 hi.iCtrlId = GetWindowLongA( msg->hwnd, GWL_ID );
422 hi.hItemHandle = msg->hwnd;
423 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
424 hi.MousePos = msg->pt;
425 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
429 if (HOOK_CallHooksA( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
430 LOWORD(msg->wParam), msg->lParam ))
432 /* skip this message */
433 HOOK_CallHooksA( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam );
440 /***********************************************************************
441 * process_raw_mouse_message
443 * returns TRUE if the contents of 'msg' should be passed to the application
445 static BOOL process_raw_mouse_message( MSG *msg, ULONG_PTR extra_info )
452 /* find the window to dispatch this mouse message to */
455 if (!(msg->hwnd = PERQDATA_GetCaptureWnd( &ht )))
457 /* If no capture HWND, find window which contains the mouse position.
458 * Also find the position of the cursor hot spot (hittest) */
459 HWND hWndScope = (HWND)extra_info;
461 if (!IsWindow(hWndScope)) hWndScope = 0;
462 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
463 msg->hwnd = GetDesktopWindow();
467 if (HOOK_IsHooked( WH_JOURNALRECORD ))
470 event.message = msg->message;
471 event.time = msg->time;
472 event.hwnd = msg->hwnd;
473 event.paramL = msg->pt.x;
474 event.paramH = msg->pt.y;
475 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
478 /* translate double clicks */
480 if ((msg->message == WM_LBUTTONDOWN) ||
481 (msg->message == WM_RBUTTONDOWN) ||
482 (msg->message == WM_MBUTTONDOWN))
485 /* translate double clicks -
486 * note that ...MOUSEMOVEs can slip in between
487 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
489 if (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS || ht != HTCLIENT )
491 if ((msg->message == clk_msg.message) &&
492 (msg->hwnd == clk_msg.hwnd) &&
493 (msg->time - clk_msg.time < doubleClickSpeed) &&
494 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
495 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
497 msg->message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
502 /* update static double click conditions */
503 if (update) clk_msg = *msg;
507 if (hittest != HTCLIENT)
509 msg->message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
510 msg->wParam = hittest;
512 else ScreenToClient( msg->hwnd, &pt );
513 msg->lParam = MAKELONG( pt.x, pt.y );
518 /***********************************************************************
519 * process_cooked_mouse_message
521 * returns TRUE if the contents of 'msg' should be passed to the application
523 static BOOL process_cooked_mouse_message( MSG *msg, BOOL remove )
525 INT hittest = HTCLIENT;
526 UINT raw_message = msg->message;
529 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
531 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
532 hittest = msg->wParam;
534 if (raw_message == WM_LBUTTONDBLCLK ||
535 raw_message == WM_RBUTTONDBLCLK ||
536 raw_message == WM_MBUTTONDBLCLK)
538 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
541 if (HOOK_IsHooked( WH_MOUSE ))
543 MOUSEHOOKSTRUCT hook;
545 hook.hwnd = msg->hwnd;
546 hook.wHitTestCode = hittest;
547 hook.dwExtraInfo = 0;
548 if (HOOK_CallHooksA( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
549 msg->message, (LPARAM)&hook ))
552 hook.hwnd = msg->hwnd;
553 hook.wHitTestCode = hittest;
554 hook.dwExtraInfo = 0;
555 HOOK_CallHooksA( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook );
560 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
562 SendMessageA( msg->hwnd, WM_SETCURSOR, msg->hwnd, MAKELONG( hittest, raw_message ));
566 if (!remove || GetCapture()) return TRUE;
570 if ((raw_message == WM_LBUTTONDOWN) ||
571 (raw_message == WM_RBUTTONDOWN) ||
572 (raw_message == WM_MBUTTONDOWN))
574 HWND hwndTop = WIN_GetTopParent( msg->hwnd );
576 /* Send the WM_PARENTNOTIFY,
577 * note that even for double/nonclient clicks
578 * notification message is still WM_L/M/RBUTTONDOWN.
580 MSG_SendParentNotify( msg->hwnd, raw_message, 0, msg->pt );
582 /* Activate the window if needed */
584 if (msg->hwnd != GetActiveWindow() && hwndTop != GetDesktopWindow())
586 LONG ret = SendMessageA( msg->hwnd, WM_MOUSEACTIVATE, hwndTop,
587 MAKELONG( hittest, raw_message ) );
591 case MA_NOACTIVATEANDEAT:
596 case MA_ACTIVATEANDEAT:
600 if (hwndTop != GetForegroundWindow() )
602 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
607 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
613 /* send the WM_SETCURSOR message */
615 /* Windows sends the normal mouse message as the message parameter
616 in the WM_SETCURSOR message even if it's non-client mouse message */
617 SendMessageA( msg->hwnd, WM_SETCURSOR, msg->hwnd, MAKELONG( hittest, raw_message ));
623 /***********************************************************************
624 * process_hardware_message
626 * returns TRUE if the contents of 'msg' should be passed to the application
628 static BOOL process_raw_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd_filter,
629 UINT first, UINT last, BOOL remove )
631 if (is_keyboard_message( msg->message ))
633 if (!process_raw_keyboard_message( msg, extra_info )) return FALSE;
635 else if (is_mouse_message( msg->message ))
637 if (!process_raw_mouse_message( msg, extra_info )) return FALSE;
641 ERR( "unknown message type %x\n", msg->message );
645 /* check destination thread and filters */
646 if (!check_message_filter( msg, hwnd_filter, first, last ) ||
647 GetWindowThreadProcessId( msg->hwnd, NULL ) != GetCurrentThreadId())
649 /* queue it for later, or for another thread */
650 queue_hardware_message( msg, extra_info, COOKED_HW_MESSAGE );
654 /* save the message in the cooked queue if we didn't want to remove it */
655 if (!remove) queue_hardware_message( msg, extra_info, COOKED_HW_MESSAGE );
660 /***********************************************************************
661 * process_cooked_hardware_message
663 * returns TRUE if the contents of 'msg' should be passed to the application
665 static BOOL process_cooked_hardware_message( MSG *msg, BOOL remove )
667 if (is_keyboard_message( msg->message ))
668 return process_cooked_keyboard_message( msg, remove );
670 if (is_mouse_message( msg->message ))
671 return process_cooked_mouse_message( msg, remove );
673 ERR( "unknown message type %x\n", msg->message );
678 /***********************************************************************
679 * handle_sent_message
681 * Handle the reception of a sent message by calling the corresponding window proc
683 static void handle_sent_message( MSG *msg, int type, ULONG_PTR extra_info )
686 MESSAGEQUEUE *queue = QUEUE_Lock( GetFastQueue16() );
687 ULONG_PTR old_extra_info = queue->GetMessageExtraInfoVal; /* save ExtraInfo */
688 WND *wndPtr = WIN_FindWndPtr( msg->hwnd );
690 TRACE( "got hwnd %x msg %x (%s) wp %x lp %lx\n",
691 msg->hwnd, msg->message, SPY_GetMsgName(msg->message),
692 msg->wParam, msg->lParam );
694 queue->GetMessageExtraInfoVal = extra_info;
696 /* call the right version of CallWindowProcXX */
700 result = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
702 (UINT16) msg->message,
707 result = CallWindowProcA( wndPtr->winproc, msg->hwnd, msg->message,
708 msg->wParam, msg->lParam );
711 result = CallWindowProcW( wndPtr->winproc, msg->hwnd, msg->message,
712 msg->wParam, msg->lParam );
716 queue->GetMessageExtraInfoVal = old_extra_info; /* Restore extra info */
717 WIN_ReleaseWndPtr(wndPtr);
718 QUEUE_Unlock( queue );
720 SERVER_START_REQ( reply_message )
722 req->result = result;
730 /***********************************************************************
731 * process_sent_messages
733 * Process all pending sent messages
735 static void process_sent_messages(void)
740 ULONG_PTR extra_info;
744 SERVER_START_REQ( get_message )
746 req->flags = GET_MSG_REMOVE | GET_MSG_SENT_ONLY;
750 if (!(res = SERVER_CALL()))
754 msg.message = req->msg;
755 msg.wParam = req->wparam;
756 msg.lParam = req->lparam;
757 msg.time = req->time;
760 extra_info = req->info;
766 handle_sent_message( &msg, type, extra_info );
772 /***********************************************************************
775 * Peek for a message matching the given parameters. Return FALSE if none available.
777 static BOOL peek_message( HWND hwnd, UINT first, UINT last, int flags, int type,
778 MSG *msg, ULONG_PTR *extra_info )
781 enum message_kind kind;
784 if (!first && !last) last = ~0;
788 SERVER_START_REQ( get_message )
792 req->get_first = first;
793 req->get_last = last;
794 if ((ret = !SERVER_CALL()))
797 msg_type = req->type;
798 msg->hwnd = req->win;
799 msg->message = req->msg;
800 msg->wParam = req->wparam;
801 msg->lParam = req->lparam;
802 msg->time = req->time;
805 *extra_info = req->info;
810 if (!ret) return FALSE;
815 handle_sent_message( msg, msg_type, *extra_info );
818 /* try to convert message to requested type */
819 if (!MSG_ConvertMsg( msg, msg_type, type ))
821 ERR( "Message %s of wrong type contains pointer parameters. Skipped!\n",
822 SPY_GetMsgName(msg->message));
824 flags |= GET_MSG_REMOVE_LAST;
829 if (!process_raw_hardware_message( msg, *extra_info,
830 hwnd, first, last, flags & GET_MSG_REMOVE ))
833 case COOKED_HW_MESSAGE:
834 if (!process_cooked_hardware_message( msg, flags & GET_MSG_REMOVE ))
836 flags |= GET_MSG_REMOVE_LAST;
842 /* now we got something */
843 TRACE( "got hwnd %x msg %x (%s) wp %x lp %lx\n",
844 msg->hwnd, msg->message, SPY_GetMsgName(msg->message),
845 msg->wParam, msg->lParam );
851 /***********************************************************************
854 * See "Windows Internals", p.447
857 * 0 if exit with timeout
860 static int wait_queue_bits( WORD bits, DWORD timeout )
865 TRACE_(msg)("q %04x waiting for %04x\n", GetFastQueue16(), bits);
867 hQueue = GetFastQueue16();
868 if (!(queue = QUEUE_Lock( hQueue ))) return 0;
872 unsigned int wake_bits = 0, changed_bits = 0;
875 SERVER_START_REQ( set_queue_mask )
877 req->wake_mask = QS_SENDMESSAGE;
878 req->changed_mask = bits | QS_SENDMESSAGE;
882 wake_bits = req->wake_bits;
883 changed_bits = req->changed_bits;
888 if (changed_bits & bits)
890 /* One of the bits is set; we can return */
891 QUEUE_Unlock( queue );
894 if (wake_bits & QS_SENDMESSAGE)
896 /* Process the sent message immediately */
897 process_sent_messages();
898 continue; /* nested sm crux */
901 TRACE_(msg)("(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
902 queue->self, bits, wake_bits, changed_bits );
904 ReleaseThunkLock( &dwlc );
905 if (dwlc) TRACE_(msg)("had win16 lock\n");
907 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
908 USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue, timeout, 0, 0 );
910 WaitForSingleObject( queue->server_queue, timeout );
911 if (dwlc) RestoreThunkLock( dwlc );
916 /**********************************************************************
917 * SetDoubleClickTime (USER.20)
919 void WINAPI SetDoubleClickTime16( UINT16 interval )
921 SetDoubleClickTime( interval );
925 /**********************************************************************
926 * SetDoubleClickTime (USER32.@)
928 BOOL WINAPI SetDoubleClickTime( UINT interval )
930 doubleClickSpeed = interval ? interval : 500;
935 /**********************************************************************
936 * GetDoubleClickTime (USER.21)
938 UINT16 WINAPI GetDoubleClickTime16(void)
940 return doubleClickSpeed;
944 /**********************************************************************
945 * GetDoubleClickTime (USER32.@)
947 UINT WINAPI GetDoubleClickTime(void)
949 return doubleClickSpeed;
953 /***********************************************************************
954 * MSG_SendMessageInterThread
956 * Implementation of an inter-task SendMessage.
958 * 0 if error or timeout
961 static LRESULT MSG_SendMessageInterThread( DWORD dest_tid, HWND hwnd, UINT msg,
962 WPARAM wParam, LPARAM lParam,
963 DWORD timeout, WORD type,
970 TRACE( "hwnd %x msg %x (%s) wp %x lp %lx\n", hwnd, msg, SPY_GetMsgName(msg), wParam, lParam );
972 SERVER_START_REQ( send_message )
974 req->kind = SEND_MESSAGE;
975 req->id = (void *)dest_tid;
979 req->wparam = wParam;
980 req->lparam = lParam;
983 req->time = GetCurrentTime();
985 ret = !SERVER_CALL_ERR();
990 iWndsLocks = WIN_SuspendWndsLock();
992 /* wait for the result */
993 wait_queue_bits( QS_SMRESULT, timeout );
995 SERVER_START_REQ( get_message_reply )
998 if ((ret = !SERVER_CALL_ERR())) result = req->result;
1002 TRACE( "hwnd %x msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1003 hwnd, msg, SPY_GetMsgName(msg), wParam, lParam, result, GetLastError() );
1005 if (!ret && (GetLastError() == ERROR_IO_PENDING))
1007 if (timeout == INFINITE) ERR("no timeout but no result\n");
1008 SetLastError(0); /* timeout */
1011 if (pRes) *pRes = result;
1013 WIN_RestoreWndsLock(iWndsLocks);
1018 /***********************************************************************
1019 * ReplyMessage (USER.115)
1021 void WINAPI ReplyMessage16( LRESULT result )
1023 ReplyMessage( result );
1026 /***********************************************************************
1027 * ReplyMessage (USER32.@)
1029 BOOL WINAPI ReplyMessage( LRESULT result )
1032 SERVER_START_REQ( reply_message )
1034 req->result = result;
1036 ret = !SERVER_CALL_ERR();
1042 /***********************************************************************
1045 static BOOL MSG_ConvertMsg( MSG *msg, int srcType, int dstType )
1047 if (srcType == QMSG_WIN32A || dstType == QMSG_WIN32A)
1049 /* posted messages are always either Win16 or Unicode Win32,
1050 * QMSG_WIN32A is only for sent messages */
1051 ERR( "invalid type %d/%d\n", srcType, dstType );
1055 if (!srcType || srcType == dstType) return TRUE;
1057 if (srcType == QMSG_WIN16)
1059 if (dstType == QMSG_WIN32W)
1061 switch ( WINPROC_MapMsg16To32W( msg->hwnd, msg->message, msg->wParam,
1062 &msg->message, &msg->wParam, &msg->lParam ) )
1067 /* Pointer messages were mapped --> need to free allocated memory and fail */
1068 WINPROC_UnmapMsg16To32W( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
1074 else if (srcType == QMSG_WIN32W)
1076 if (dstType == QMSG_WIN16)
1081 mp16.lParam = msg->lParam;
1082 switch ( WINPROC_MapMsg32WTo16( msg->hwnd, msg->message, msg->wParam,
1083 &msg16, &mp16.wParam, &mp16.lParam ) )
1086 msg->message = msg16;
1087 msg->wParam = mp16.wParam;
1088 msg->lParam = mp16.lParam;
1091 /* Pointer messages were mapped --> need to free allocated memory and fail */
1092 WINPROC_UnmapMsg32WTo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
1099 FIXME( "Invalid message type(s): %d / %d\n", srcType, dstType );
1104 /***********************************************************************
1107 static BOOL MSG_PeekMessage( int type, LPMSG msg_out, HWND hwnd,
1108 DWORD first, DWORD last, WORD flags, BOOL peek )
1110 int mask, msg_flags = 0;
1111 MESSAGEQUEUE *msgQueue;
1114 ULONG_PTR extra_info;
1116 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
1119 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
1120 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
1121 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
1122 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
1123 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
1124 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
1126 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
1128 if (IsTaskLocked16()) flags |= PM_NOYIELD;
1130 iWndsLocks = WIN_SuspendWndsLock();
1132 /* check for graphics events */
1133 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
1134 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
1136 if (flags & PM_REMOVE) msg_flags |= GET_MSG_REMOVE;
1140 if (peek_message( hwnd, first, last, msg_flags, type, &msg, &extra_info ))
1142 /* need to fill the window handle for WM_PAINT message */
1143 if (msg.message == WM_PAINT)
1145 if ((msg.hwnd = WIN_FindWinToRepaint( hwnd )))
1147 if (IsIconic( msg.hwnd ) && GetClassLongA( msg.hwnd, GCL_HICON ))
1149 msg.message = WM_PAINTICON;
1152 if( !hwnd || msg.hwnd == hwnd || IsChild(hwnd,msg.hwnd) )
1154 /* clear internal paint flag */
1155 RedrawWindow( msg.hwnd, NULL, 0,
1156 RDW_NOINTERNALPAINT | RDW_NOCHILDREN );
1164 /* FIXME: should be done before checking for hw events */
1165 MSG_JournalPlayBackMsg();
1170 if (!(flags & PM_NOYIELD)) UserYield16();
1172 WIN_RestoreWndsLock(iWndsLocks);
1176 wait_queue_bits( mask, INFINITE );
1179 WIN_RestoreWndsLock(iWndsLocks);
1181 if ((msgQueue = QUEUE_Lock( GetFastQueue16() )))
1183 msgQueue->GetMessageTimeVal = msg.time;
1184 msgQueue->GetMessagePosVal = MAKELONG( msg.pt.x, msg.pt.y );
1185 msgQueue->GetMessageExtraInfoVal = extra_info;
1186 QUEUE_Unlock( msgQueue );
1189 /* We got a message */
1190 if (flags & PM_REMOVE)
1192 if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN)
1194 BYTE *p = &QueueKeyStateTable[msg.wParam & 0xff];
1200 else if (msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP)
1201 QueueKeyStateTable[msg.wParam & 0xff] &= ~0x80;
1204 /* copy back our internal safe copy of message data to msg_out.
1205 * msg_out is a variable from the *program*, so it can't be used
1206 * internally as it can get "corrupted" by our use of SendMessage()
1207 * (back to the program) inside the message handling itself. */
1213 return (msg.message != WM_QUIT);
1216 /***********************************************************************
1217 * MSG_InternalGetMessage
1219 * GetMessage() function for internal use. Behave like GetMessage(),
1220 * but also call message filters and optionally send WM_ENTERIDLE messages.
1221 * 'hwnd' must be the handle of the dialog or menu window.
1222 * 'code' is the message filter value (MSGF_??? codes).
1224 BOOL MSG_InternalGetMessage( MSG *msg, HWND hwnd, HWND hwndOwner, UINT first, UINT last,
1225 WPARAM code, WORD flags, BOOL sendIdle, BOOL* idleSent )
1231 if (!MSG_PeekMessage( QMSG_WIN32W, msg, 0, first, last, flags, TRUE ))
1233 /* No message present -> send ENTERIDLE and wait */
1234 if (IsWindow(hwndOwner))
1236 SendMessageA( hwndOwner, WM_ENTERIDLE,
1237 code, (LPARAM)hwnd );
1242 MSG_PeekMessage( QMSG_WIN32W, msg, 0, first, last, flags, FALSE );
1245 else /* Always wait for a message */
1246 MSG_PeekMessage( QMSG_WIN32W, msg, 0, first, last, flags, FALSE );
1248 /* Call message filters */
1250 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
1254 if (HOOK_CallHooksW( WH_SYSMSGFILTER, code, 0, (LPARAM)&tmp_msg ) ||
1255 HOOK_CallHooksW( WH_MSGFILTER, code, 0, (LPARAM)&tmp_msg ))
1257 /* Message filtered -> remove it from the queue if it's still there. */
1258 if (!(flags & PM_REMOVE))
1259 MSG_PeekMessage( QMSG_WIN32W, msg, 0, first, last, PM_REMOVE, TRUE );
1263 /* need to return an ASCII message (FIXME) */
1264 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
1265 return (msg->message != WM_QUIT);
1270 /***********************************************************************
1271 * PeekMessage32 (USER.819)
1273 BOOL16 WINAPI PeekMessage32_16( SEGPTR msg16_32, HWND16 hwnd,
1274 UINT16 first, UINT16 last, UINT16 flags,
1275 BOOL16 wHaveParamHigh )
1278 MSG32_16 *lpmsg16_32 = MapSL(msg16_32);
1281 ret = MSG_PeekMessage( QMSG_WIN16, &msg, hwnd, first, last, flags, TRUE );
1283 lpmsg16_32->msg.hwnd = msg.hwnd;
1284 lpmsg16_32->msg.message = msg.message;
1285 lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
1286 lpmsg16_32->msg.lParam = msg.lParam;
1287 lpmsg16_32->msg.time = msg.time;
1288 lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
1289 lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
1291 if ( wHaveParamHigh )
1292 lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
1294 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg16_32 );
1298 /***********************************************************************
1299 * PeekMessage (USER.109)
1301 BOOL16 WINAPI PeekMessage16( SEGPTR msg, HWND16 hwnd,
1302 UINT16 first, UINT16 last, UINT16 flags )
1304 return PeekMessage32_16( msg, hwnd, first, last, flags, FALSE );
1307 /***********************************************************************
1308 * PeekMessageA (USER32.@)
1310 BOOL WINAPI PeekMessageA( LPMSG lpmsg, HWND hwnd, UINT min, UINT max, UINT flags )
1312 BOOL ret = PeekMessageW( lpmsg, hwnd, min, max, flags );
1313 if (ret) lpmsg->wParam = map_wparam_WtoA( lpmsg->message, lpmsg->wParam );
1317 /***********************************************************************
1318 * PeekMessageW (USER32.@) Check queue for messages
1320 * Checks for a message in the thread's queue, filtered as for
1321 * GetMessage(). Returns immediately whether a message is available
1324 * Whether a retrieved message is removed from the queue is set by the
1325 * _wRemoveMsg_ flags, which should be one of the following values:
1327 * PM_NOREMOVE Do not remove the message from the queue.
1329 * PM_REMOVE Remove the message from the queue.
1331 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1332 * request that the system not yield control during PeekMessage();
1333 * however applications may not rely on scheduling behavior.
1337 * Nonzero if a message is available and is retrieved, zero otherwise.
1344 BOOL WINAPI PeekMessageW(
1345 LPMSG lpmsg, /* [out] buffer to receive message */
1346 HWND hwnd, /* [in] restrict to messages for hwnd */
1347 UINT min, /* [in] minimum message to receive */
1348 UINT max, /* [in] maximum message to receive */
1349 UINT wRemoveMsg /* [in] removal flags */
1352 BOOL ret = MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1353 if (ret) HOOK_CallHooksW( WH_GETMESSAGE, HC_ACTION,
1354 wRemoveMsg & PM_REMOVE, (LPARAM)lpmsg );
1359 /***********************************************************************
1360 * GetMessage32 (USER.820)
1362 BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1363 UINT16 last, BOOL16 wHaveParamHigh )
1365 MSG32_16 *lpmsg16_32 = MapSL(msg16_32);
1368 MSG_PeekMessage( QMSG_WIN16, &msg, hWnd, first, last, PM_REMOVE, FALSE );
1370 lpmsg16_32->msg.hwnd = msg.hwnd;
1371 lpmsg16_32->msg.message = msg.message;
1372 lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
1373 lpmsg16_32->msg.lParam = msg.lParam;
1374 lpmsg16_32->msg.time = msg.time;
1375 lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
1376 lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
1378 if ( wHaveParamHigh )
1379 lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
1381 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1382 lpmsg16_32->msg.message, hWnd, first, last );
1384 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)msg16_32 );
1385 return lpmsg16_32->msg.message != WM_QUIT;
1388 /***********************************************************************
1389 * GetMessage (USER.108)
1391 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
1393 return GetMessage32_16( msg, hwnd, first, last, FALSE );
1396 /***********************************************************************
1397 * GetMessageA (USER32.@)
1399 BOOL WINAPI GetMessageA( MSG *lpmsg, HWND hwnd, UINT min, UINT max )
1401 GetMessageW( lpmsg, hwnd, min, max );
1402 lpmsg->wParam = map_wparam_WtoA( lpmsg->message, lpmsg->wParam );
1403 return lpmsg->message != WM_QUIT;
1406 /***********************************************************************
1407 * GetMessageW (USER32.@) Retrieve next message
1409 * GetMessage retrieves the next event from the calling thread's
1410 * queue and deposits it in *lpmsg.
1412 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1413 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1414 * all application messages are retrieved.
1416 * _min_ and _max_ specify the range of messages of interest. If
1417 * min==max==0, no filtering is performed. Useful examples are
1418 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1419 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1421 * WM_PAINT messages are not removed from the queue; they remain until
1422 * processed. Other messages are removed from the queue.
1426 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1433 BOOL WINAPI GetMessageW(
1434 MSG* lpmsg, /* [out] buffer to receive message */
1435 HWND hwnd, /* [in] restrict to messages for hwnd */
1436 UINT min, /* [in] minimum message to receive */
1437 UINT max /* [in] maximum message to receive */
1440 MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1442 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1443 lpmsg->message, hwnd, min, max );
1445 HOOK_CallHooksW( WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)lpmsg );
1446 return lpmsg->message != WM_QUIT;
1449 /***********************************************************************
1452 static BOOL MSG_PostToQueue( DWORD tid, int type, HWND hwnd,
1453 UINT message, WPARAM wParam, LPARAM lParam )
1457 TRACE( "posting %x %x (%s) %x %lx\n", hwnd, message, SPY_GetMsgName(message), wParam, lParam );
1459 SERVER_START_REQ( send_message )
1461 req->kind = POST_MESSAGE;
1462 req->id = (void *)tid;
1466 req->wparam = wParam;
1467 req->lparam = lParam;
1470 req->time = GetCurrentTime();
1472 res = SERVER_CALL();
1478 if (res == STATUS_INVALID_PARAMETER)
1479 SetLastError( ERROR_INVALID_THREAD_ID );
1481 SetLastError( RtlNtStatusToDosError(res) );
1487 /***********************************************************************
1490 static BOOL MSG_PostMessage( int type, HWND hwnd, UINT message,
1491 WPARAM wParam, LPARAM lParam )
1495 if (hwnd == HWND_BROADCAST)
1497 WND *pDesktop = WIN_GetDesktop();
1498 TRACE("HWND_BROADCAST !\n");
1500 for (wndPtr=WIN_LockWndPtr(pDesktop->child); wndPtr; WIN_UpdateWndPtr(&wndPtr,wndPtr->next))
1502 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1504 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1505 wndPtr->hwndSelf, message, wParam, lParam);
1506 MSG_PostToQueue( GetWindowThreadProcessId( wndPtr->hwndSelf, NULL ), type,
1507 wndPtr->hwndSelf, message, wParam, lParam );
1510 WIN_ReleaseDesktop();
1511 TRACE("End of HWND_BROADCAST !\n");
1515 return MSG_PostToQueue( GetWindowThreadProcessId( hwnd, NULL ),
1516 type, hwnd, message, wParam, lParam );
1520 /***********************************************************************
1521 * PostMessage (USER.110)
1523 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1526 return (BOOL16) MSG_PostMessage( QMSG_WIN16, hwnd, message, wParam, lParam );
1529 /***********************************************************************
1530 * PostMessageA (USER32.@)
1532 BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
1535 return PostMessageW( hwnd, message, map_wparam_AtoW( message, wParam ), lParam );
1538 /***********************************************************************
1539 * PostMessageW (USER32.@)
1541 BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
1544 /* See thread on wine-devel around 6.2.2001. Basically posted messages
1545 * that are known to contain pointers are dropped by the Windows 32bit
1546 * PostMessage() with return FALSE; and invalid parameter last error.
1547 * (tested against NT4 by Gerard Patel)
1549 if (is_pointer_message(message))
1551 SetLastError(ERROR_INVALID_PARAMETER);
1554 return MSG_PostMessage( QMSG_WIN32W, hwnd, message, wParam, lParam );
1557 /***********************************************************************
1558 * PostAppMessage (USER.116)
1559 * PostAppMessage16 (USER32.@)
1561 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message,
1562 WPARAM16 wParam, LPARAM lParam )
1564 TDB *pTask = TASK_GetPtr( hTask );
1565 if (!pTask) return FALSE;
1566 return MSG_PostToQueue( (DWORD)pTask->teb->tid, QMSG_WIN16, 0, message, wParam, lParam );
1569 /**********************************************************************
1570 * PostThreadMessageA (USER32.@)
1572 BOOL WINAPI PostThreadMessageA( DWORD idThread, UINT message,
1573 WPARAM wParam, LPARAM lParam )
1575 return PostThreadMessageW( idThread, message, map_wparam_AtoW( message, wParam ), lParam );
1578 /**********************************************************************
1579 * PostThreadMessageW (USER32.@)
1581 BOOL WINAPI PostThreadMessageW( DWORD idThread, UINT message,
1582 WPARAM wParam, LPARAM lParam )
1584 if (is_pointer_message( message ))
1586 SetLastError( ERROR_INVALID_PARAMETER );
1589 return MSG_PostToQueue( idThread, QMSG_WIN32W, 0, message, wParam, lParam );
1593 /************************************************************************
1594 * MSG_CallWndProcHook32
1596 static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
1600 cwp.lParam = pmsg->lParam;
1601 cwp.wParam = pmsg->wParam;
1602 cwp.message = pmsg->message;
1603 cwp.hwnd = pmsg->hwnd;
1605 if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1606 else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1608 pmsg->lParam = cwp.lParam;
1609 pmsg->wParam = cwp.wParam;
1610 pmsg->message = cwp.message;
1611 pmsg->hwnd = cwp.hwnd;
1615 /***********************************************************************
1618 * return values: 0 if timeout occurs
1621 static LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
1622 LPARAM lParam, DWORD timeout, WORD type,
1626 WND **list, **ppWnd;
1631 if (pRes) *pRes = 0;
1633 if (hwnd == HWND_BROADCAST|| hwnd == HWND_TOPMOST)
1635 if (pRes) *pRes = 1;
1637 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1639 WIN_ReleaseDesktop();
1642 WIN_ReleaseDesktop();
1644 TRACE("HWND_BROADCAST !\n");
1645 for (ppWnd = list; *ppWnd; ppWnd++)
1647 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
1648 if (!IsWindow(wndPtr->hwndSelf)) continue;
1649 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1651 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1652 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1653 MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
1654 timeout, type, pRes);
1657 WIN_ReleaseWndPtr(wndPtr);
1658 WIN_ReleaseWinArray(list);
1659 TRACE("End of HWND_BROADCAST !\n");
1663 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1671 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1673 pmsg->hwnd = hwnd & 0xffff;
1674 pmsg->message= msg & 0xffff;
1675 pmsg->wParam = wParam & 0xffff;
1676 pmsg->lParam = lParam;
1677 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1678 (LPARAM)SEGPTR_GET(pmsg) );
1680 msg = pmsg->message;
1681 wParam = pmsg->wParam;
1682 lParam = pmsg->lParam;
1683 SEGPTR_FREE( pmsg );
1688 MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
1691 MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
1696 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1698 WARN("invalid hwnd %04x\n", hwnd );
1701 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1703 WIN_ReleaseWndPtr( wndPtr );
1704 return 0; /* Don't send anything if the task is dying */
1706 winproc = (WNDPROC)wndPtr->winproc;
1707 WIN_ReleaseWndPtr( wndPtr );
1709 if (type != QMSG_WIN16)
1710 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
1712 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1714 dest_tid = GetWindowThreadProcessId( hwnd, NULL );
1715 if (dest_tid && dest_tid != GetCurrentThreadId())
1717 ret = MSG_SendMessageInterThread( dest_tid, hwnd, msg,
1718 wParam, lParam, timeout, type, pRes );
1724 /* Call the right CallWindowProc flavor */
1728 res = CallWindowProc16( (WNDPROC16)winproc, hwnd, msg, wParam, lParam );
1731 res = CallWindowProcA( winproc, hwnd, msg, wParam, lParam );
1734 res = CallWindowProcW( winproc, hwnd, msg, wParam, lParam );
1737 if (pRes) *pRes = res;
1740 if (type != QMSG_WIN16)
1741 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, pRes?*pRes:0, wParam, lParam );
1743 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, pRes?*pRes:0, wParam, lParam );
1749 /***********************************************************************
1750 * SendMessage (USER.111)
1752 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1756 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, QMSG_WIN16, &res);
1761 /***********************************************************************
1762 * SendMessageA (USER32.@)
1764 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
1769 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, QMSG_WIN32A, &res);
1775 /***********************************************************************
1776 * SendMessageW (USER32.@) Send Window Message
1778 * Sends a message to the window procedure of the specified window.
1779 * SendMessage() will not return until the called window procedure
1780 * either returns or calls ReplyMessage().
1782 * Use PostMessage() to send message and return immediately. A window
1783 * procedure may use InSendMessage() to detect
1784 * SendMessage()-originated messages.
1786 * Applications which communicate via HWND_BROADCAST may use
1787 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1788 * with other applications.
1794 LRESULT WINAPI SendMessageW(
1795 HWND hwnd, /* [in] Window to send message to. If HWND_BROADCAST,
1796 the message will be sent to all top-level windows. */
1798 UINT msg, /* [in] message */
1799 WPARAM wParam, /* [in] message parameter */
1800 LPARAM lParam /* [in] additional message parameter */
1804 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, QMSG_WIN32W, &res);
1810 /***********************************************************************
1811 * SendMessageTimeout (not a WINAPI)
1813 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1814 LPARAM lParam, UINT16 flags,
1815 UINT16 timeout, LPWORD resultp)
1820 /* FIXME: need support for SMTO_BLOCK */
1822 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, QMSG_WIN16, &msgRet);
1823 if (resultp) *resultp = (WORD) msgRet;
1828 /***********************************************************************
1829 * SendMessageTimeoutA (USER32.@)
1831 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
1832 LPARAM lParam, UINT flags,
1833 UINT timeout, LPDWORD resultp)
1838 /* FIXME: need support for SMTO_BLOCK */
1840 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, QMSG_WIN32A, &msgRet);
1842 if (resultp) *resultp = (DWORD) msgRet;
1847 /***********************************************************************
1848 * SendMessageTimeoutW (USER32.@)
1850 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
1851 LPARAM lParam, UINT flags,
1852 UINT timeout, LPDWORD resultp)
1857 /* FIXME: need support for SMTO_BLOCK */
1859 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, QMSG_WIN32W, &msgRet);
1861 if (resultp) *resultp = (DWORD) msgRet;
1866 /***********************************************************************
1867 * WaitMessage (USER.112) (USER32.@) Suspend thread pending messages
1869 * WaitMessage() suspends a thread until events appear in the thread's
1872 BOOL WINAPI WaitMessage(void)
1874 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
1878 /***********************************************************************
1879 * MsgWaitForMultipleObjectsEx (USER32.@)
1881 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
1882 DWORD timeout, DWORD mask, DWORD flags )
1884 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
1886 HQUEUE16 hQueue = GetFastQueue16();
1887 MESSAGEQUEUE *msgQueue;
1889 if (count > MAXIMUM_WAIT_OBJECTS-1)
1891 SetLastError( ERROR_INVALID_PARAMETER );
1895 if (!(msgQueue = QUEUE_Lock( hQueue ))) return WAIT_FAILED;
1897 /* set the queue mask */
1898 SERVER_START_REQ( set_queue_mask )
1900 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
1901 req->changed_mask = mask;
1907 /* Add the thread event to the handle list */
1908 for (i = 0; i < count; i++) handles[i] = pHandles[i];
1909 handles[count] = msgQueue->server_queue;
1912 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
1914 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
1915 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
1918 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
1919 timeout, flags & MWMO_ALERTABLE );
1920 QUEUE_Unlock( msgQueue );
1925 /***********************************************************************
1926 * MsgWaitForMultipleObjects (USER32.@)
1928 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
1929 BOOL wait_all, DWORD timeout, DWORD mask )
1931 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
1932 wait_all ? MWMO_WAITALL : 0 );
1936 /***********************************************************************
1937 * MsgWaitForMultipleObjects16 (USER.640)
1939 DWORD WINAPI MsgWaitForMultipleObjects16( DWORD count, CONST HANDLE *handles,
1940 BOOL wait_all, DWORD timeout, DWORD mask )
1942 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
1943 wait_all ? MWMO_WAITALL : 0 );
1947 /***********************************************************************
1948 * WaitForInputIdle (USER32.@)
1950 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
1952 DWORD cur_time, ret;
1953 HANDLE idle_event = -1;
1955 SERVER_START_REQ( wait_input_idle )
1957 req->handle = hProcess;
1958 req->timeout = dwTimeOut;
1959 if (!(ret = SERVER_CALL_ERR())) idle_event = req->event;
1962 if (ret) return 0xffffffff; /* error */
1963 if (!idle_event) return 0; /* no event to wait on */
1965 cur_time = GetTickCount();
1967 TRACE("waiting for %x\n", idle_event );
1968 while ( dwTimeOut > GetTickCount() - cur_time || dwTimeOut == INFINITE )
1970 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut, QS_SENDMESSAGE );
1971 if ( ret == ( WAIT_OBJECT_0 + 1 ))
1973 process_sent_messages();
1976 if ( ret == WAIT_TIMEOUT || ret == 0xFFFFFFFF )
1978 TRACE("timeout or error\n");
1983 TRACE("finished\n");
1988 return WAIT_TIMEOUT;
1992 /***********************************************************************
1993 * UserYield (USER.332)
1994 * UserYield16 (USER32.@)
1996 void WINAPI UserYield16(void)
1998 /* Handle sent messages */
1999 process_sent_messages();
2004 /* Handle sent messages again */
2005 process_sent_messages();
2016 static const struct accent_char accent_chars[] =
2018 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
2019 {'`', 'A', '\300'}, {'`', 'a', '\340'},
2020 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
2021 {'^', 'A', '\302'}, {'^', 'a', '\342'},
2022 {'~', 'A', '\303'}, {'~', 'a', '\343'},
2023 {'"', 'A', '\304'}, {'"', 'a', '\344'},
2024 {'O', 'A', '\305'}, {'o', 'a', '\345'},
2025 {'0', 'A', '\305'}, {'0', 'a', '\345'},
2026 {'A', 'A', '\305'}, {'a', 'a', '\345'},
2027 {'A', 'E', '\306'}, {'a', 'e', '\346'},
2028 {',', 'C', '\307'}, {',', 'c', '\347'},
2029 {'`', 'E', '\310'}, {'`', 'e', '\350'},
2030 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
2031 {'^', 'E', '\312'}, {'^', 'e', '\352'},
2032 {'"', 'E', '\313'}, {'"', 'e', '\353'},
2033 {'`', 'I', '\314'}, {'`', 'i', '\354'},
2034 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
2035 {'^', 'I', '\316'}, {'^', 'i', '\356'},
2036 {'"', 'I', '\317'}, {'"', 'i', '\357'},
2037 {'-', 'D', '\320'}, {'-', 'd', '\360'},
2038 {'~', 'N', '\321'}, {'~', 'n', '\361'},
2039 {'`', 'O', '\322'}, {'`', 'o', '\362'},
2040 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
2041 {'^', 'O', '\324'}, {'^', 'o', '\364'},
2042 {'~', 'O', '\325'}, {'~', 'o', '\365'},
2043 {'"', 'O', '\326'}, {'"', 'o', '\366'},
2044 {'/', 'O', '\330'}, {'/', 'o', '\370'},
2045 {'`', 'U', '\331'}, {'`', 'u', '\371'},
2046 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
2047 {'^', 'U', '\333'}, {'^', 'u', '\373'},
2048 {'"', 'U', '\334'}, {'"', 'u', '\374'},
2049 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
2050 {'T', 'H', '\336'}, {'t', 'h', '\376'},
2051 {'s', 's', '\337'}, {'"', 'y', '\377'},
2052 {'s', 'z', '\337'}, {'i', 'j', '\377'},
2053 /* iso-8859-2 uses this */
2054 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
2055 {'<', 'S', '\251'}, {'<', 's', '\271'},
2056 {'<', 'T', '\253'}, {'<', 't', '\273'},
2057 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
2058 {'<', 'C', '\310'}, {'<', 'c', '\350'},
2059 {'<', 'E', '\314'}, {'<', 'e', '\354'},
2060 {'<', 'D', '\317'}, {'<', 'd', '\357'},
2061 {'<', 'N', '\322'}, {'<', 'n', '\362'},
2062 {'<', 'R', '\330'}, {'<', 'r', '\370'},
2063 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
2064 {';', 'E', '\312'}, {';', 'e', '\332'},
2065 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
2066 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
2067 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
2068 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
2069 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
2070 /* collision whith S, from iso-8859-9 !!! */
2071 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
2072 {',', 'T', '\336'}, {',', 't', '\376'},
2073 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
2074 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2075 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2076 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2077 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2078 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2079 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2080 /* iso-8859-3 uses this */
2081 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2082 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2083 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2084 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2085 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2086 {'>', 'S', '\336'}, {'>', 's', '\376'},
2087 /* collision whith G( from iso-8859-9 !!! */
2088 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2089 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2090 /* collision whith I. from iso-8859-3 !!! */
2091 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2092 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2093 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2094 /* iso-8859-4 uses this */
2095 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2096 {',', 'L', '\246'}, {',', 'l', '\266'},
2097 {',', 'G', '\253'}, {',', 'g', '\273'},
2098 {',', 'N', '\321'}, {',', 'n', '\361'},
2099 {',', 'K', '\323'}, {',', 'k', '\363'},
2100 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2101 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2102 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2103 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2104 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2105 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2106 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2107 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2108 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2109 {';', 'U', '\331'}, {';', 'u', '\371'},
2110 /* iso-8859-9 uses this */
2111 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2112 * whith the same letters on other iso-8859-x (that is they are on
2113 * different places :-( ), if you use turkish uncomment these and
2114 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2115 * FIXME: should be dynamic according to chosen language
2116 * if/when Wine has turkish support.
2118 /* collision whith G( from iso-8859-3 !!! */
2119 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2120 /* collision whith S, from iso-8859-2 !!! */
2121 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2122 /* collision whith I. from iso-8859-3 !!! */
2123 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
2127 /***********************************************************************
2128 * MSG_DoTranslateMessage
2130 * Implementation of TranslateMessage.
2132 * TranslateMessage translates virtual-key messages into character-messages,
2134 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2135 * ditto replacing WM_* with WM_SYS*
2136 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2137 * by the keyboard driver.
2139 static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
2140 WPARAM wParam, LPARAM lParam )
2142 static int dead_char;
2145 if (message != WM_MOUSEMOVE && message != WM_TIMER)
2146 TRACE("(%s, %04X, %08lX)\n",
2147 SPY_GetMsgName(message), wParam, lParam );
2148 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
2149 TRACE_(key)("(%s, %04X, %08lX)\n",
2150 SPY_GetMsgName(message), wParam, lParam );
2152 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
2154 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
2155 SPY_GetVKeyName(wParam), wParam, LOBYTE(HIWORD(lParam)));
2157 /* FIXME : should handle ToUnicode yielding 2 */
2158 switch (ToUnicode(wParam, HIWORD(lParam), QueueKeyStateTable, wp, 2, 0))
2161 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2162 /* Should dead chars handling go in ToAscii ? */
2167 if (wp[0] == ' ') wp[0] = dead_char;
2168 if (dead_char == 0xa2) dead_char = '(';
2169 else if (dead_char == 0xa8) dead_char = '"';
2170 else if (dead_char == 0xb2) dead_char = ';';
2171 else if (dead_char == 0xb4) dead_char = '\'';
2172 else if (dead_char == 0xb7) dead_char = '<';
2173 else if (dead_char == 0xb8) dead_char = ',';
2174 else if (dead_char == 0xff) dead_char = '.';
2175 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
2176 if ((accent_chars[i].ac_accent == dead_char) &&
2177 (accent_chars[i].ac_char == wp[0]))
2179 wp[0] = accent_chars[i].ac_result;
2184 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2185 PostMessageW( hwnd, message, wp[0], lParam );
2189 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2191 TRACE_(key)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2192 PostMessageW( hwnd, message, wp[0], lParam );
2199 /***********************************************************************
2200 * TranslateMessage (USER.113)
2202 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
2204 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2205 msg->wParam, msg->lParam );
2209 /***********************************************************************
2210 * TranslateMessage32 (USER.821)
2212 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
2217 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
2219 wParam = (WPARAM)msg->msg.wParam;
2221 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
2222 wParam, msg->msg.lParam );
2225 /***********************************************************************
2226 * TranslateMessage (USER32.@)
2228 BOOL WINAPI TranslateMessage( const MSG *msg )
2230 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2231 msg->wParam, msg->lParam );
2235 /***********************************************************************
2236 * DispatchMessage (USER.114)
2238 LONG WINAPI DispatchMessage16( const MSG16* msg )
2244 /* Process timer messages */
2245 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2249 /* before calling window proc, verify whether timer is still valid;
2250 there's a slim chance that the application kills the timer
2251 between GetMessage and DispatchMessage API calls */
2252 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
2253 return 0; /* invalid winproc */
2255 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
2256 msg->message, msg->wParam, GetTickCount() );
2260 if (!msg->hwnd) return 0;
2261 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2262 if (!wndPtr->winproc)
2267 painting = (msg->message == WM_PAINT);
2268 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2270 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
2271 msg->wParam, msg->lParam );
2272 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
2273 msg->hwnd, msg->message,
2274 msg->wParam, msg->lParam );
2275 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval,
2276 msg->wParam, msg->lParam );
2278 WIN_ReleaseWndPtr(wndPtr);
2279 wndPtr = WIN_FindWndPtr(msg->hwnd);
2280 if (painting && wndPtr &&
2281 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2283 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2285 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2286 /* Validate the update region to avoid infinite WM_PAINT loop */
2287 RedrawWindow( wndPtr->hwndSelf, NULL, 0,
2288 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
2291 WIN_ReleaseWndPtr(wndPtr);
2296 /***********************************************************************
2297 * DispatchMessage32 (USER.822)
2299 LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
2301 if (wHaveParamHigh == FALSE)
2302 return DispatchMessage16(&(lpmsg16_32->msg));
2307 msg.hwnd = lpmsg16_32->msg.hwnd;
2308 msg.message = lpmsg16_32->msg.message;
2309 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
2310 msg.lParam = lpmsg16_32->msg.lParam;
2311 msg.time = lpmsg16_32->msg.time;
2312 msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
2313 msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
2314 return DispatchMessageA(&msg);
2318 /***********************************************************************
2319 * DispatchMessageA (USER32.@)
2321 LONG WINAPI DispatchMessageA( const MSG* msg )
2327 /* Process timer messages */
2328 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2332 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2334 /* before calling window proc, verify whether timer is still valid;
2335 there's a slim chance that the application kills the timer
2336 between GetMessage and DispatchMessage API calls */
2337 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
2338 return 0; /* invalid winproc */
2340 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2341 msg->message, msg->wParam, GetTickCount() );
2345 if (!msg->hwnd) return 0;
2346 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2347 if (!wndPtr->winproc)
2352 painting = (msg->message == WM_PAINT);
2353 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2354 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2356 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2357 msg->wParam, msg->lParam );
2358 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
2359 msg->hwnd, msg->message,
2360 msg->wParam, msg->lParam );
2361 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2362 msg->wParam, msg->lParam );
2364 WIN_ReleaseWndPtr(wndPtr);
2365 wndPtr = WIN_FindWndPtr(msg->hwnd);
2367 if (painting && wndPtr &&
2368 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2370 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2372 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2373 /* Validate the update region to avoid infinite WM_PAINT loop */
2374 RedrawWindow( wndPtr->hwndSelf, NULL, 0,
2375 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
2378 WIN_ReleaseWndPtr(wndPtr);
2383 /***********************************************************************
2384 * DispatchMessageW (USER32.@) Process Message
2386 * Process the message specified in the structure *_msg_.
2388 * If the lpMsg parameter points to a WM_TIMER message and the
2389 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2390 * points to the function that is called instead of the window
2393 * The message must be valid.
2397 * DispatchMessage() returns the result of the window procedure invoked.
2404 LONG WINAPI DispatchMessageW( const MSG* msg )
2410 /* Process timer messages */
2411 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2415 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2417 /* before calling window proc, verify whether timer is still valid;
2418 there's a slim chance that the application kills the timer
2419 between GetMessage and DispatchMessage API calls */
2420 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
2421 return 0; /* invalid winproc */
2423 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2424 msg->message, msg->wParam, GetTickCount() );
2428 if (!msg->hwnd) return 0;
2429 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2430 if (!wndPtr->winproc)
2435 painting = (msg->message == WM_PAINT);
2436 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2437 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2439 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2440 msg->wParam, msg->lParam );
2441 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
2442 msg->hwnd, msg->message,
2443 msg->wParam, msg->lParam );
2444 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2445 msg->wParam, msg->lParam );
2447 WIN_ReleaseWndPtr(wndPtr);
2448 wndPtr = WIN_FindWndPtr(msg->hwnd);
2450 if (painting && wndPtr &&
2451 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2453 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2455 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2456 /* Validate the update region to avoid infinite WM_PAINT loop */
2457 RedrawWindow( wndPtr->hwndSelf, NULL, 0,
2458 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
2461 WIN_ReleaseWndPtr(wndPtr);
2466 /***********************************************************************
2467 * RegisterWindowMessage (USER.118)
2468 * RegisterWindowMessageA (USER32.@)
2470 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
2472 TRACE("%s\n", str );
2473 return GlobalAddAtomA( str );
2477 /***********************************************************************
2478 * RegisterWindowMessageW (USER32.@)
2480 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
2482 TRACE("%p\n", str );
2483 return GlobalAddAtomW( str );
2487 /***********************************************************************
2488 * InSendMessage (USER.192)
2490 BOOL16 WINAPI InSendMessage16(void)
2492 return InSendMessage();
2496 /***********************************************************************
2497 * InSendMessage (USER32.@)
2499 BOOL WINAPI InSendMessage(void)
2501 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2505 /***********************************************************************
2506 * InSendMessageEx (USER32.@)
2508 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2511 SERVER_START_REQ( in_send_message )
2513 if (!SERVER_CALL_ERR()) ret = req->flags;
2520 /***********************************************************************
2521 * BroadcastSystemMessage (USER32.@)
2523 LONG WINAPI BroadcastSystemMessage(
2524 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
2527 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2528 dwFlags,*recipients,uMessage,wParam,lParam
2533 /***********************************************************************
2534 * SendNotifyMessageA (USER32.@)
2536 BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2538 return MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, QMSG_WIN32A, NULL);
2541 /***********************************************************************
2542 * SendNotifyMessageW (USER32.@)
2544 BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2546 return MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, QMSG_WIN32W, NULL);
2549 /***********************************************************************
2550 * SendMessageCallbackA (USER32.@)
2551 * FIXME: It's like PostMessage. The callback gets called when the message
2552 * is processed. We have to modify the message processing for an exact
2554 * The callback is only called when the thread that called us calls one of
2555 * Get/Peek/WaitMessage.
2557 BOOL WINAPI SendMessageCallbackA(
2558 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2559 FARPROC lpResultCallBack,DWORD dwData)
2561 FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2562 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2563 if ( hWnd == HWND_BROADCAST)
2564 { PostMessageA( hWnd, Msg, wParam, lParam);
2565 FIXME("Broadcast: Callback will not be called!\n");
2568 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2571 /***********************************************************************
2572 * SendMessageCallbackW (USER32.@)
2573 * FIXME: see SendMessageCallbackA.
2575 BOOL WINAPI SendMessageCallbackW(
2576 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2577 FARPROC lpResultCallBack,DWORD dwData)
2579 FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2580 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2581 if ( hWnd == HWND_BROADCAST)
2582 { PostMessageW( hWnd, Msg, wParam, lParam);
2583 FIXME("Broadcast: Callback will not be called!\n");
2586 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));