2 * Message queues related functions
4 * Copyright 1993, 1994 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
26 #ifdef HAVE_SYS_TIME_H
27 # include <sys/time.h>
29 #include <sys/types.h>
36 #include "wine/server.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
48 WINE_DECLARE_DEBUG_CHANNEL(key
);
50 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
51 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
54 /***********************************************************************
57 inline static BOOL
is_keyboard_message( UINT message
)
59 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
63 /***********************************************************************
66 inline static BOOL
is_mouse_message( UINT message
)
68 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
69 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
73 /***********************************************************************
74 * check_message_filter
76 inline static BOOL
check_message_filter( const MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
80 if (msg
->hwnd
!= hwnd
&& !IsChild( hwnd
, msg
->hwnd
)) return FALSE
;
84 return (msg
->message
>= first
&& msg
->message
<= last
);
90 /***********************************************************************
91 * process_sent_messages
93 * Process all pending sent messages.
95 inline static void process_sent_messages(void)
98 MSG_peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
102 /***********************************************************************
103 * queue_hardware_message
105 * store a hardware message in the thread queue
108 static void queue_hardware_message( MSG
*msg
, ULONG_PTR extra_info
)
110 SERVER_START_REQ( send_message
)
112 req
->type
= MSG_HARDWARE
;
113 req
->id
= GetWindowThreadProcessId( msg
->hwnd
, NULL
);
114 req
->win
= msg
->hwnd
;
115 req
->msg
= msg
->message
;
116 req
->wparam
= msg
->wParam
;
117 req
->lparam
= msg
->lParam
;
120 req
->time
= msg
->time
;
121 req
->info
= extra_info
;
123 wine_server_call( req
);
130 /***********************************************************************
131 * MSG_SendParentNotify
133 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
134 * the window has the WS_EX_NOPARENTNOTIFY style.
136 static void MSG_SendParentNotify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
138 /* pt has to be in the client coordinates of the parent window */
139 MapWindowPoints( 0, hwnd
, &pt
, 1 );
144 if (!(GetWindowLongA( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
145 if (GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
146 if (!(parent
= GetParent(hwnd
))) break;
147 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
149 SendMessageA( hwnd
, WM_PARENTNOTIFY
,
150 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
155 #if 0 /* this is broken for now, will require proper support in the server */
157 /***********************************************************************
158 * MSG_JournalPlayBackMsg
160 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
162 void MSG_JournalPlayBackMsg(void)
169 wtime
=HOOK_CallHooks( WH_JOURNALPLAYBACK
, HC_GETNEXT
, 0, (LPARAM
)&tmpMsg
, TRUE
);
170 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
174 msg
.message
= tmpMsg
.message
;
175 msg
.hwnd
= tmpMsg
.hwnd
;
176 msg
.time
= tmpMsg
.time
;
177 if ((tmpMsg
.message
>= WM_KEYFIRST
) && (tmpMsg
.message
<= WM_KEYLAST
))
179 msg
.wParam
= tmpMsg
.paramL
& 0xFF;
180 msg
.lParam
= MAKELONG(tmpMsg
.paramH
&0x7ffff,tmpMsg
.paramL
>>8);
181 if (tmpMsg
.message
== WM_KEYDOWN
|| tmpMsg
.message
== WM_SYSKEYDOWN
)
183 for (keyDown
=i
=0; i
<256 && !keyDown
; i
++)
184 if (InputKeyStateTable
[i
] & 0x80)
187 msg
.lParam
|= 0x40000000;
188 InputKeyStateTable
[msg
.wParam
] |= 0x80;
189 AsyncKeyStateTable
[msg
.wParam
] |= 0x80;
191 else /* WM_KEYUP, WM_SYSKEYUP */
193 msg
.lParam
|= 0xC0000000;
194 InputKeyStateTable
[msg
.wParam
] &= ~0x80;
196 if (InputKeyStateTable
[VK_MENU
] & 0x80)
197 msg
.lParam
|= 0x20000000;
198 if (tmpMsg
.paramH
& 0x8000) /*special_key bit*/
199 msg
.lParam
|= 0x01000000;
201 msg
.pt
.x
= msg
.pt
.y
= 0;
202 queue_hardware_message( &msg
, 0 );
204 else if ((tmpMsg
.message
>= WM_MOUSEFIRST
) && (tmpMsg
.message
<= WM_MOUSELAST
))
206 switch (tmpMsg
.message
)
209 InputKeyStateTable
[VK_LBUTTON
] |= 0x80;
210 AsyncKeyStateTable
[VK_LBUTTON
] |= 0x80;
213 InputKeyStateTable
[VK_LBUTTON
] &= ~0x80;
216 InputKeyStateTable
[VK_MBUTTON
] |= 0x80;
217 AsyncKeyStateTable
[VK_MBUTTON
] |= 0x80;
220 InputKeyStateTable
[VK_MBUTTON
] &= ~0x80;
223 InputKeyStateTable
[VK_RBUTTON
] |= 0x80;
224 AsyncKeyStateTable
[VK_RBUTTON
] |= 0x80;
227 InputKeyStateTable
[VK_RBUTTON
] &= ~0x80;
230 SetCursorPos(tmpMsg
.paramL
,tmpMsg
.paramH
);
231 msg
.lParam
=MAKELONG(tmpMsg
.paramL
,tmpMsg
.paramH
);
233 if (InputKeyStateTable
[VK_LBUTTON
] & 0x80) msg
.wParam
|= MK_LBUTTON
;
234 if (InputKeyStateTable
[VK_MBUTTON
] & 0x80) msg
.wParam
|= MK_MBUTTON
;
235 if (InputKeyStateTable
[VK_RBUTTON
] & 0x80) msg
.wParam
|= MK_RBUTTON
;
237 msg
.pt
.x
= tmpMsg
.paramL
;
238 msg
.pt
.y
= tmpMsg
.paramH
;
239 queue_hardware_message( &msg
, 0 );
241 HOOK_CallHooks( WH_JOURNALPLAYBACK
, HC_SKIP
, 0, (LPARAM
)&tmpMsg
, TRUE
);
245 if( tmpMsg
.message
== WM_QUEUESYNC
) HOOK_CallHooks( WH_CBT
, HCBT_QS
, 0, 0, TRUE
);
251 /***********************************************************************
252 * process_raw_keyboard_message
254 * returns TRUE if the contents of 'msg' should be passed to the application
256 static void process_raw_keyboard_message( MSG
*msg
)
260 event
.message
= msg
->message
;
261 event
.hwnd
= msg
->hwnd
;
262 event
.time
= msg
->time
;
263 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
264 event
.paramH
= msg
->lParam
& 0x7FFF;
265 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
266 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
270 /***********************************************************************
271 * process_cooked_keyboard_message
273 * returns TRUE if the contents of 'msg' should be passed to the application
275 static BOOL
process_cooked_keyboard_message( MSG
*msg
, BOOL remove
)
279 /* Handle F1 key by sending out WM_HELP message */
280 if ((msg
->message
== WM_KEYUP
) &&
281 (msg
->wParam
== VK_F1
) &&
282 (msg
->hwnd
!= GetDesktopWindow()) &&
283 !MENU_IsMenuActive())
286 hi
.cbSize
= sizeof(HELPINFO
);
287 hi
.iContextType
= HELPINFO_WINDOW
;
288 hi
.iCtrlId
= GetWindowLongA( msg
->hwnd
, GWL_ID
);
289 hi
.hItemHandle
= msg
->hwnd
;
290 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
291 hi
.MousePos
= msg
->pt
;
292 SendMessageA(msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
296 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
297 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
299 /* skip this message */
300 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
307 /***********************************************************************
308 * process_raw_mouse_message
310 static void process_raw_mouse_message( MSG
*msg
, BOOL remove
)
318 HWND hWndScope
= msg
->hwnd
;
320 /* find the window to dispatch this mouse message to */
323 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
324 if (!(msg
->hwnd
= info
.hwndCapture
))
326 /* If no capture HWND, find window which contains the mouse position.
327 * Also find the position of the cursor hot spot (hittest) */
328 if (!IsWindow(hWndScope
)) hWndScope
= 0;
329 if (!(msg
->hwnd
= WINPOS_WindowFromPoint( hWndScope
, msg
->pt
, &hittest
)))
330 msg
->hwnd
= GetDesktopWindow();
333 event
.message
= msg
->message
;
334 event
.time
= msg
->time
;
335 event
.hwnd
= msg
->hwnd
;
336 event
.paramL
= msg
->pt
.x
;
337 event
.paramH
= msg
->pt
.y
;
338 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
340 /* translate double clicks */
342 if ((msg
->message
== WM_LBUTTONDOWN
) ||
343 (msg
->message
== WM_RBUTTONDOWN
) ||
344 (msg
->message
== WM_MBUTTONDOWN
))
346 BOOL update
= remove
;
347 /* translate double clicks -
348 * note that ...MOUSEMOVEs can slip in between
349 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
351 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
352 hittest
!= HTCLIENT
||
353 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
355 if ((msg
->message
== clk_msg
.message
) &&
356 (msg
->hwnd
== clk_msg
.hwnd
) &&
357 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
358 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
359 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
361 msg
->message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
369 /* update static double click conditions */
370 if (update
) clk_msg
= *msg
;
374 /* Note: windows has no concept of a non-client wheel message */
375 if (hittest
!= HTCLIENT
&& msg
->message
!= WM_MOUSEWHEEL
)
377 msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
378 msg
->wParam
= hittest
;
382 /* coordinates don't get translated while tracking a menu */
383 /* FIXME: should differentiate popups and top-level menus */
384 if (!(info
.flags
& GUI_INMENUMODE
)) ScreenToClient( msg
->hwnd
, &pt
);
386 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
390 /***********************************************************************
391 * process_cooked_mouse_message
393 * returns TRUE if the contents of 'msg' should be passed to the application
395 static BOOL
process_cooked_mouse_message( MSG
*msg
, ULONG_PTR extra_info
, BOOL remove
)
397 MOUSEHOOKSTRUCT hook
;
398 INT hittest
= HTCLIENT
;
399 UINT raw_message
= msg
->message
;
402 if (msg
->message
>= WM_NCMOUSEFIRST
&& msg
->message
<= WM_NCMOUSELAST
)
404 raw_message
+= WM_MOUSEFIRST
- WM_NCMOUSEFIRST
;
405 hittest
= msg
->wParam
;
407 if (raw_message
== WM_LBUTTONDBLCLK
||
408 raw_message
== WM_RBUTTONDBLCLK
||
409 raw_message
== WM_MBUTTONDBLCLK
)
411 raw_message
+= WM_LBUTTONDOWN
- WM_LBUTTONDBLCLK
;
415 hook
.hwnd
= msg
->hwnd
;
416 hook
.wHitTestCode
= hittest
;
417 hook
.dwExtraInfo
= extra_info
;
418 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
419 msg
->message
, (LPARAM
)&hook
, TRUE
))
422 hook
.hwnd
= msg
->hwnd
;
423 hook
.wHitTestCode
= hittest
;
424 hook
.dwExtraInfo
= extra_info
;
425 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, msg
->message
, (LPARAM
)&hook
, TRUE
);
429 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
431 SendMessageA( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
432 MAKELONG( hittest
, raw_message
));
436 if (!remove
|| GetCapture()) return TRUE
;
440 if ((raw_message
== WM_LBUTTONDOWN
) ||
441 (raw_message
== WM_RBUTTONDOWN
) ||
442 (raw_message
== WM_MBUTTONDOWN
))
444 /* Send the WM_PARENTNOTIFY,
445 * note that even for double/nonclient clicks
446 * notification message is still WM_L/M/RBUTTONDOWN.
448 MSG_SendParentNotify( msg
->hwnd
, raw_message
, 0, msg
->pt
);
450 /* Activate the window if needed */
452 if (msg
->hwnd
!= GetActiveWindow())
454 HWND hwndTop
= msg
->hwnd
;
457 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
458 hwndTop
= GetParent( hwndTop
);
461 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
463 LONG ret
= SendMessageA( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
464 MAKELONG( hittest
, raw_message
) );
467 case MA_NOACTIVATEANDEAT
:
472 case MA_ACTIVATEANDEAT
:
477 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
480 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret
);
487 /* send the WM_SETCURSOR message */
489 /* Windows sends the normal mouse message as the message parameter
490 in the WM_SETCURSOR message even if it's non-client mouse message */
491 SendMessageA( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
492 MAKELONG( hittest
, raw_message
));
498 /***********************************************************************
499 * process_hardware_message
501 * returns TRUE if the contents of 'msg' should be passed to the application
503 BOOL
MSG_process_raw_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, HWND hwnd_filter
,
504 UINT first
, UINT last
, BOOL remove
)
506 if (is_keyboard_message( msg
->message
))
508 process_raw_keyboard_message( msg
);
510 else if (is_mouse_message( msg
->message
))
512 process_raw_mouse_message( msg
, remove
);
516 ERR( "unknown message type %x\n", msg
->message
);
519 return check_message_filter( msg
, hwnd_filter
, first
, last
);
523 /***********************************************************************
524 * MSG_process_cooked_hardware_message
526 * returns TRUE if the contents of 'msg' should be passed to the application
528 BOOL
MSG_process_cooked_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, BOOL remove
)
530 if (is_keyboard_message( msg
->message
))
531 return process_cooked_keyboard_message( msg
, remove
);
533 if (is_mouse_message( msg
->message
))
534 return process_cooked_mouse_message( msg
, extra_info
, remove
);
536 ERR( "unknown message type %x\n", msg
->message
);
541 /***********************************************************************
542 * WaitMessage (USER.112) Suspend thread pending messages
543 * WaitMessage (USER32.@) Suspend thread pending messages
545 * WaitMessage() suspends a thread until events appear in the thread's
548 BOOL WINAPI
WaitMessage(void)
550 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
554 /***********************************************************************
555 * MsgWaitForMultipleObjectsEx (USER32.@)
557 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
558 DWORD timeout
, DWORD mask
, DWORD flags
)
560 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
562 MESSAGEQUEUE
*msgQueue
;
564 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
566 SetLastError( ERROR_INVALID_PARAMETER
);
570 if (!(msgQueue
= QUEUE_Current())) return WAIT_FAILED
;
572 /* set the queue mask */
573 SERVER_START_REQ( set_queue_mask
)
575 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
576 req
->changed_mask
= mask
;
578 wine_server_call( req
);
582 /* Add the thread event to the handle list */
583 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
584 handles
[count
] = msgQueue
->server_queue
;
586 ReleaseThunkLock( &lock
);
587 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
589 ret
= USER_Driver
.pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
590 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
593 ret
= WaitForMultipleObjectsEx( count
+1, handles
, flags
& MWMO_WAITALL
,
594 timeout
, flags
& MWMO_ALERTABLE
);
595 if (lock
) RestoreThunkLock( lock
);
600 /***********************************************************************
601 * MsgWaitForMultipleObjects (USER32.@)
603 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
604 BOOL wait_all
, DWORD timeout
, DWORD mask
)
606 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
607 wait_all
? MWMO_WAITALL
: 0 );
611 /***********************************************************************
612 * WaitForInputIdle (USER32.@)
614 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
616 DWORD start_time
, elapsed
, ret
;
617 HANDLE idle_event
= (HANDLE
)-1;
619 SERVER_START_REQ( wait_input_idle
)
621 req
->handle
= hProcess
;
622 req
->timeout
= dwTimeOut
;
623 if (!(ret
= wine_server_call_err( req
))) idle_event
= reply
->event
;
626 if (ret
) return WAIT_FAILED
; /* error */
627 if (!idle_event
) return 0; /* no event to wait on */
629 start_time
= GetTickCount();
632 TRACE("waiting for %p\n", idle_event
);
635 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
638 case WAIT_OBJECT_0
+1:
639 process_sent_messages();
643 TRACE("timeout or error\n");
649 if (dwTimeOut
!= INFINITE
)
651 elapsed
= GetTickCount() - start_time
;
652 if (elapsed
> dwTimeOut
)
662 /***********************************************************************
663 * UserYield (USER.332)
665 void WINAPI
UserYield16(void)
669 /* Handle sent messages */
670 process_sent_messages();
673 ReleaseThunkLock(&count
);
676 RestoreThunkLock(count
);
677 /* Handle sent messages again */
678 process_sent_messages();
683 /***********************************************************************
684 * TranslateMessage (USER32.@)
686 * Implementation of TranslateMessage.
688 * TranslateMessage translates virtual-key messages into character-messages,
690 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
691 * ditto replacing WM_* with WM_SYS*
692 * This produces WM_CHAR messages only for keys mapped to ASCII characters
693 * by the keyboard driver.
695 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
696 * return value is nonzero, regardless of the translation.
699 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
706 if (msg
->message
>= WM_KEYFIRST
&& msg
->message
<= WM_KEYLAST
)
708 TRACE_(key
)("(%s, %04X, %08lX)\n",
709 SPY_GetMsgName(msg
->message
, msg
->hwnd
), msg
->wParam
, msg
->lParam
);
711 /* Return code must be TRUE no matter what! */
715 if ((msg
->message
!= WM_KEYDOWN
) && (msg
->message
!= WM_SYSKEYDOWN
)) return rc
;
717 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
718 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
720 GetKeyboardState( state
);
721 /* FIXME : should handle ToUnicode yielding 2 */
722 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
725 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
726 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
727 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
728 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
732 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
733 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
734 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
735 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
742 /***********************************************************************
743 * DispatchMessageA (USER32.@)
745 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
752 /* Process timer messages */
753 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
757 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
759 /* before calling window proc, verify whether timer is still valid;
760 there's a slim chance that the application kills the timer
761 between GetMessage and DispatchMessage API calls */
762 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (WNDPROC
)msg
->lParam
))
763 return 0; /* invalid winproc */
765 return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
766 msg
->message
, msg
->wParam
, GetTickCount() );
770 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
772 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
775 if (wndPtr
== WND_OTHER_PROCESS
)
777 if (IsWindow( msg
->hwnd
))
778 ERR( "cannot dispatch msg to other process window %p\n", msg
->hwnd
);
779 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
782 if (!(winproc
= wndPtr
->winproc
))
784 WIN_ReleasePtr( wndPtr
);
787 painting
= (msg
->message
== WM_PAINT
);
788 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
789 WIN_ReleasePtr( wndPtr
);
790 /* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
792 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
793 msg
->wParam
, msg
->lParam
);
794 retval
= CallWindowProcA( winproc
, msg
->hwnd
, msg
->message
,
795 msg
->wParam
, msg
->lParam
);
796 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
797 msg
->wParam
, msg
->lParam
);
799 if (painting
&& (wndPtr
= WIN_GetPtr( msg
->hwnd
)) && (wndPtr
!= WND_OTHER_PROCESS
))
801 BOOL validate
= ((wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
);
802 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
803 WIN_ReleasePtr( wndPtr
);
806 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg
->hwnd
);
807 /* Validate the update region to avoid infinite WM_PAINT loop */
808 RedrawWindow( msg
->hwnd
, NULL
, 0,
809 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
816 /***********************************************************************
817 * DispatchMessageW (USER32.@) Process Message
819 * Process the message specified in the structure *_msg_.
821 * If the lpMsg parameter points to a WM_TIMER message and the
822 * parameter of the WM_TIMER message is not NULL, the lParam parameter
823 * points to the function that is called instead of the window
826 * The message must be valid.
830 * DispatchMessage() returns the result of the window procedure invoked.
837 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
844 /* Process timer messages */
845 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
849 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
851 /* before calling window proc, verify whether timer is still valid;
852 there's a slim chance that the application kills the timer
853 between GetMessage and DispatchMessage API calls */
854 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (WNDPROC
)msg
->lParam
))
855 return 0; /* invalid winproc */
857 return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
858 msg
->message
, msg
->wParam
, GetTickCount() );
862 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
864 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
867 if (wndPtr
== WND_OTHER_PROCESS
)
869 if (IsWindow( msg
->hwnd
))
870 ERR( "cannot dispatch msg to other process window %p\n", msg
->hwnd
);
871 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
874 if (!(winproc
= wndPtr
->winproc
))
876 WIN_ReleasePtr( wndPtr
);
879 painting
= (msg
->message
== WM_PAINT
);
880 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
881 WIN_ReleasePtr( wndPtr
);
882 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
884 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
885 msg
->wParam
, msg
->lParam
);
886 retval
= CallWindowProcW( winproc
, msg
->hwnd
, msg
->message
,
887 msg
->wParam
, msg
->lParam
);
888 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
889 msg
->wParam
, msg
->lParam
);
891 if (painting
&& (wndPtr
= WIN_GetPtr( msg
->hwnd
)) && (wndPtr
!= WND_OTHER_PROCESS
))
893 BOOL validate
= ((wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
);
894 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
895 WIN_ReleasePtr( wndPtr
);
898 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg
->hwnd
);
899 /* Validate the update region to avoid infinite WM_PAINT loop */
900 RedrawWindow( msg
->hwnd
, NULL
, 0,
901 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
908 /***********************************************************************
909 * RegisterWindowMessage (USER.118)
910 * RegisterWindowMessageA (USER32.@)
912 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
915 return GlobalAddAtomA( str
);
919 /***********************************************************************
920 * RegisterWindowMessageW (USER32.@)
922 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
925 return GlobalAddAtomW( str
);
929 /***********************************************************************
930 * BroadcastSystemMessage (USER32.@)
931 * BroadcastSystemMessageA (USER32.@)
933 LONG WINAPI
BroadcastSystemMessage(
934 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
937 if ((*recipients
& BSM_APPLICATIONS
)||
938 (*recipients
== BSM_ALLCOMPONENTS
))
940 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n",
941 dwFlags
,*recipients
,uMessage
,wParam
,lParam
);
942 PostMessageA(HWND_BROADCAST
,uMessage
,wParam
,lParam
);
947 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
948 dwFlags
,*recipients
,uMessage
,wParam
,lParam
);
953 /***********************************************************************
954 * BroadcastSystemMessageW (USER32.@)
956 LONG WINAPI
BroadcastSystemMessageW(
957 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
960 if ((*recipients
& BSM_APPLICATIONS
)||
961 (*recipients
== BSM_ALLCOMPONENTS
))
963 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n",
964 dwFlags
,*recipients
,uMessage
,wParam
,lParam
);
965 PostMessageW(HWND_BROADCAST
,uMessage
,wParam
,lParam
);
970 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
971 dwFlags
,*recipients
,uMessage
,wParam
,lParam
);