2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
5 * FILE: subsys/win32k/ntuser/message.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
11 /* INCLUDES ******************************************************************/
18 #define PM_BADMSGFLAGS ~((QS_RAWINPUT << 16)|PM_QS_SENDMESSAGE|PM_QS_PAINT|PM_QS_POSTMESSAGE|PM_QS_INPUT|PM_NOYIELD|PM_REMOVE)
26 DOSENDMESSAGE
, *PDOSENDMESSAGE
;
28 /* FUNCTIONS *****************************************************************/
31 IntInitMessageImpl(VOID
)
33 return STATUS_SUCCESS
;
37 IntCleanupMessageImpl(VOID
)
39 return STATUS_SUCCESS
;
42 #define MMS_SIZE_WPARAM -1
43 #define MMS_SIZE_WPARAMWCHAR -2
44 #define MMS_SIZE_LPARAMSZ -3
45 #define MMS_SIZE_SPECIAL -4
46 #define MMS_FLAG_READ 0x01
47 #define MMS_FLAG_WRITE 0x02
48 #define MMS_FLAG_READWRITE (MMS_FLAG_READ | MMS_FLAG_WRITE)
49 typedef struct tagMSGMEMORY
55 MSGMEMORY
, *PMSGMEMORY
;
57 static MSGMEMORY MsgMemory
[] =
59 { WM_CREATE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
60 { WM_DDE_ACK
, sizeof(KMDDELPARAM
), MMS_FLAG_READ
},
61 { WM_DDE_EXECUTE
, MMS_SIZE_WPARAM
, MMS_FLAG_READ
},
62 { WM_GETMINMAXINFO
, sizeof(MINMAXINFO
), MMS_FLAG_READWRITE
},
63 { WM_GETTEXT
, MMS_SIZE_WPARAMWCHAR
, MMS_FLAG_WRITE
},
64 { WM_NCCALCSIZE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
65 { WM_NCCREATE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
66 { WM_SETTEXT
, MMS_SIZE_LPARAMSZ
, MMS_FLAG_READ
},
67 { WM_STYLECHANGED
, sizeof(STYLESTRUCT
), MMS_FLAG_READ
},
68 { WM_STYLECHANGING
, sizeof(STYLESTRUCT
), MMS_FLAG_READWRITE
},
69 { WM_COPYDATA
, MMS_SIZE_SPECIAL
, MMS_FLAG_READ
},
70 { WM_WINDOWPOSCHANGED
, sizeof(WINDOWPOS
), MMS_FLAG_READ
},
71 { WM_WINDOWPOSCHANGING
, sizeof(WINDOWPOS
), MMS_FLAG_READWRITE
},
74 static PMSGMEMORY FASTCALL
75 FindMsgMemory(UINT Msg
)
77 PMSGMEMORY MsgMemoryEntry
;
79 /* See if this message type is present in the table */
80 for (MsgMemoryEntry
= MsgMemory
;
81 MsgMemoryEntry
< MsgMemory
+ sizeof(MsgMemory
) / sizeof(MSGMEMORY
);
84 if (Msg
== MsgMemoryEntry
->Message
)
86 return MsgMemoryEntry
;
94 MsgMemorySize(PMSGMEMORY MsgMemoryEntry
, WPARAM wParam
, LPARAM lParam
)
97 PUNICODE_STRING WindowName
;
98 PUNICODE_STRING ClassName
;
103 if (MMS_SIZE_WPARAM
== MsgMemoryEntry
->Size
)
107 else if (MMS_SIZE_WPARAMWCHAR
== MsgMemoryEntry
->Size
)
109 Size
= (UINT
) (wParam
* sizeof(WCHAR
));
111 else if (MMS_SIZE_LPARAMSZ
== MsgMemoryEntry
->Size
)
113 Size
= (UINT
) ((wcslen((PWSTR
) lParam
) + 1) * sizeof(WCHAR
));
115 else if (MMS_SIZE_SPECIAL
== MsgMemoryEntry
->Size
)
117 switch(MsgMemoryEntry
->Message
)
121 Cs
= (CREATESTRUCTW
*) lParam
;
122 WindowName
= (PUNICODE_STRING
) Cs
->lpszName
;
123 ClassName
= (PUNICODE_STRING
) Cs
->lpszClass
;
124 Size
= sizeof(CREATESTRUCTW
) + WindowName
->Length
+ sizeof(WCHAR
);
125 if (IS_ATOM(ClassName
->Buffer
))
127 Size
+= sizeof(WCHAR
) + sizeof(ATOM
);
131 Size
+= sizeof(WCHAR
) + ClassName
->Length
+ sizeof(WCHAR
);
136 Size
= wParam
? sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
) : sizeof(RECT
);
140 Size
= sizeof(COPYDATASTRUCT
) + ((PCOPYDATASTRUCT
)lParam
)->cbData
;
143 case WM_COPYGLOBALDATA
:
155 Size
= MsgMemoryEntry
->Size
;
158 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
160 DPRINT1("Exception caught in MsgMemorySize()! Status: 0x%x\n", _SEH2_GetExceptionCode());
168 PackParam(LPARAM
*lParamPacked
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
170 NCCALCSIZE_PARAMS
*UnpackedNcCalcsize
;
171 NCCALCSIZE_PARAMS
*PackedNcCalcsize
;
172 CREATESTRUCTW
*UnpackedCs
;
173 CREATESTRUCTW
*PackedCs
;
174 PUNICODE_STRING WindowName
;
175 PUNICODE_STRING ClassName
;
179 *lParamPacked
= lParam
;
180 if (WM_NCCALCSIZE
== Msg
&& wParam
)
182 UnpackedNcCalcsize
= (NCCALCSIZE_PARAMS
*) lParam
;
183 if (UnpackedNcCalcsize
->lppos
!= (PWINDOWPOS
) (UnpackedNcCalcsize
+ 1))
185 PackedNcCalcsize
= ExAllocatePoolWithTag(PagedPool
,
186 sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
),
188 if (NULL
== PackedNcCalcsize
)
190 DPRINT1("Not enough memory to pack lParam\n");
191 return STATUS_NO_MEMORY
;
193 RtlCopyMemory(PackedNcCalcsize
, UnpackedNcCalcsize
, sizeof(NCCALCSIZE_PARAMS
));
194 PackedNcCalcsize
->lppos
= (PWINDOWPOS
) (PackedNcCalcsize
+ 1);
195 RtlCopyMemory(PackedNcCalcsize
->lppos
, UnpackedNcCalcsize
->lppos
, sizeof(WINDOWPOS
));
196 *lParamPacked
= (LPARAM
) PackedNcCalcsize
;
199 else if (WM_CREATE
== Msg
|| WM_NCCREATE
== Msg
)
201 UnpackedCs
= (CREATESTRUCTW
*) lParam
;
202 WindowName
= (PUNICODE_STRING
) UnpackedCs
->lpszName
;
203 ClassName
= (PUNICODE_STRING
) UnpackedCs
->lpszClass
;
204 Size
= sizeof(CREATESTRUCTW
) + WindowName
->Length
+ sizeof(WCHAR
);
205 if (IS_ATOM(ClassName
->Buffer
))
207 Size
+= sizeof(WCHAR
) + sizeof(ATOM
);
211 Size
+= sizeof(WCHAR
) + ClassName
->Length
+ sizeof(WCHAR
);
213 PackedCs
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
214 if (NULL
== PackedCs
)
216 DPRINT1("Not enough memory to pack lParam\n");
217 return STATUS_NO_MEMORY
;
219 RtlCopyMemory(PackedCs
, UnpackedCs
, sizeof(CREATESTRUCTW
));
220 CsData
= (PCHAR
) (PackedCs
+ 1);
221 PackedCs
->lpszName
= (LPCWSTR
) (CsData
- (PCHAR
) PackedCs
);
222 RtlCopyMemory(CsData
, WindowName
->Buffer
, WindowName
->Length
);
223 CsData
+= WindowName
->Length
;
224 *((WCHAR
*) CsData
) = L
'\0';
225 CsData
+= sizeof(WCHAR
);
226 PackedCs
->lpszClass
= (LPCWSTR
) (CsData
- (PCHAR
) PackedCs
);
227 if (IS_ATOM(ClassName
->Buffer
))
229 *((WCHAR
*) CsData
) = L
'A';
230 CsData
+= sizeof(WCHAR
);
231 *((ATOM
*) CsData
) = (ATOM
)(DWORD_PTR
) ClassName
->Buffer
;
232 CsData
+= sizeof(ATOM
);
236 *((WCHAR
*) CsData
) = L
'S';
237 CsData
+= sizeof(WCHAR
);
238 RtlCopyMemory(CsData
, ClassName
->Buffer
, ClassName
->Length
);
239 CsData
+= ClassName
->Length
;
240 *((WCHAR
*) CsData
) = L
'\0';
241 CsData
+= sizeof(WCHAR
);
243 ASSERT(CsData
== (PCHAR
) PackedCs
+ Size
);
244 *lParamPacked
= (LPARAM
) PackedCs
;
247 return STATUS_SUCCESS
;
251 UnpackParam(LPARAM lParamPacked
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
253 NCCALCSIZE_PARAMS
*UnpackedParams
;
254 NCCALCSIZE_PARAMS
*PackedParams
;
255 PWINDOWPOS UnpackedWindowPos
;
257 if (lParamPacked
== lParam
)
259 return STATUS_SUCCESS
;
262 if (WM_NCCALCSIZE
== Msg
&& wParam
)
264 PackedParams
= (NCCALCSIZE_PARAMS
*) lParamPacked
;
265 UnpackedParams
= (NCCALCSIZE_PARAMS
*) lParam
;
266 UnpackedWindowPos
= UnpackedParams
->lppos
;
267 RtlCopyMemory(UnpackedParams
, PackedParams
, sizeof(NCCALCSIZE_PARAMS
));
268 UnpackedParams
->lppos
= UnpackedWindowPos
;
269 RtlCopyMemory(UnpackedWindowPos
, PackedParams
+ 1, sizeof(WINDOWPOS
));
270 ExFreePool((PVOID
) lParamPacked
);
272 return STATUS_SUCCESS
;
274 else if (WM_CREATE
== Msg
|| WM_NCCREATE
== Msg
)
276 ExFreePool((PVOID
) lParamPacked
);
278 return STATUS_SUCCESS
;
283 return STATUS_INVALID_PARAMETER
;
290 ( PWINDOW_OBJECT Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
292 BOOL SameThread
= FALSE
;
294 if (Window
->pti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
297 if ((!SameThread
&& (Window
->pti
->fsHooks
& HOOKID_TO_FLAG(WH_CALLWNDPROC
))) ||
298 (SameThread
&& ISITHOOKED(WH_CALLWNDPROC
)) )
305 co_HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, SameThread
, (LPARAM
)&CWP
);
313 ( PWINDOW_OBJECT Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*uResult
)
315 BOOL SameThread
= FALSE
;
317 if (Window
->pti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
320 if ((!SameThread
&& (Window
->pti
->fsHooks
& HOOKID_TO_FLAG(WH_CALLWNDPROCRET
))) ||
321 (SameThread
&& ISITHOOKED(WH_CALLWNDPROCRET
)) )
326 CWPR
.wParam
= wParam
;
327 CWPR
.lParam
= lParam
;
328 CWPR
.lResult
= *uResult
;
329 co_HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, SameThread
, (LPARAM
)&CWPR
);
335 IntDispatchMessage(PMSG pMsg
)
337 LARGE_INTEGER TickCount
;
340 PMSGMEMORY MsgMemoryEntry
;
341 INT lParamBufferSize
;
343 PWINDOW_OBJECT Window
= NULL
;
347 Window
= UserGetWindowObject(pMsg
->hwnd
);
348 if (!Window
|| !Window
->Wnd
) return 0;
351 if (((pMsg
->message
== WM_SYSTIMER
) ||
352 (pMsg
->message
== WM_TIMER
)) &&
355 if (pMsg
->message
== WM_TIMER
)
357 if (ValidateTimerCallback(PsGetCurrentThreadWin32Thread(),Window
,pMsg
->wParam
,pMsg
->lParam
))
359 KeQueryTickCount(&TickCount
);
360 Time
= MsqCalculateMessageTime(&TickCount
);
361 return co_IntCallWindowProc((WNDPROC
)pMsg
->lParam
,
373 PTIMER pTimer
= FindSystemTimer(pMsg
);
374 if (pTimer
&& pTimer
->pfn
)
376 KeQueryTickCount(&TickCount
);
377 Time
= MsqCalculateMessageTime(&TickCount
);
378 pTimer
->pfn(pMsg
->hwnd
, WM_SYSTIMER
, (UINT
)pMsg
->wParam
, Time
);
384 if ( !Window
|| !Window
->Wnd
) return 0;
386 /* See if this message type is present in the table */
387 MsgMemoryEntry
= FindMsgMemory(pMsg
->message
);
388 if ( !MsgMemoryEntry
)
390 lParamBufferSize
= -1;
394 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, pMsg
->wParam
, pMsg
->lParam
);
397 if (! NT_SUCCESS(PackParam(&lParamPacked
, pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
)))
399 DPRINT1("Failed to pack message parameters\n");
403 retval
= co_IntCallWindowProc( Window
->Wnd
->lpfnWndProc
,
404 !Window
->Wnd
->Unicode
,
411 if (! NT_SUCCESS(UnpackParam(lParamPacked
, pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
)))
413 DPRINT1("Failed to unpack message parameters\n");
416 if (pMsg
->message
== WM_PAINT
)
418 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
419 HRGN hrgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
420 co_UserGetUpdateRgn( Window
, hrgn
, TRUE
);
421 GreDeleteObject( hrgn
);
427 co_IntSendHitTestMessages(PUSER_MESSAGE_QUEUE ThreadQueue
, LPMSG Msg
)
429 if(!Msg
->hwnd
|| ThreadQueue
->CaptureWindow
)
438 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
443 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
450 case WM_LBUTTONDBLCLK
:
451 case WM_MBUTTONDBLCLK
:
452 case WM_RBUTTONDBLCLK
:
453 case WM_XBUTTONDBLCLK
:
456 PSYSTEM_CURSORINFO CurInfo
;
457 CurInfo
= IntGetSysCursorInfo();
459 wParam
= (WPARAM
)(CurInfo
->ButtonsDown
);
461 co_IntSendMessage(Msg
->hwnd
, WM_MOUSEMOVE
, wParam
, Msg
->lParam
);
462 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
465 case WM_NCLBUTTONDOWN
:
466 case WM_NCMBUTTONDOWN
:
467 case WM_NCRBUTTONDOWN
:
468 case WM_NCXBUTTONDOWN
:
469 case WM_NCLBUTTONDBLCLK
:
470 case WM_NCMBUTTONDBLCLK
:
471 case WM_NCRBUTTONDBLCLK
:
472 case WM_NCXBUTTONDBLCLK
:
474 co_IntSendMessage(Msg
->hwnd
, WM_NCMOUSEMOVE
, (WPARAM
)Msg
->wParam
, Msg
->lParam
);
475 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
482 co_IntActivateWindowMouse(
483 PUSER_MESSAGE_QUEUE ThreadQueue
,
485 PWINDOW_OBJECT MsgWindow
,
489 PWINDOW_OBJECT Parent
;
491 ASSERT_REFS_CO(MsgWindow
);
493 if(*HitTest
== (USHORT
)HTTRANSPARENT
)
495 /* eat the message, search again! */
499 Parent
= IntGetParent(MsgWindow
);//fixme: deref retval?
501 /* If no parent window, pass MsgWindows HWND as wParam. Fixes bug #3111 */
502 Result
= co_IntSendMessage(MsgWindow
->hSelf
,
504 (WPARAM
) (Parent
? Parent
->hSelf
: MsgWindow
->hSelf
),
505 (LPARAM
)MAKELONG(*HitTest
, Msg
->message
)
510 case MA_NOACTIVATEANDEAT
:
514 case MA_ACTIVATEANDEAT
:
515 co_IntMouseActivateWindow(MsgWindow
);
519 co_IntMouseActivateWindow(MsgWindow
);
527 co_IntTranslateMouseMessage(
528 PUSER_MESSAGE_QUEUE ThreadQueue
,
533 PWINDOW_OBJECT Window
;
534 USER_REFERENCE_ENTRY Ref
, DesktopRef
;
536 if(!(Window
= UserGetWindowObject(Msg
->hwnd
)))
538 /* let's just eat the message?! */
542 UserRefObjectCo(Window
, &Ref
);
544 if ( ThreadQueue
== Window
->pti
->MessageQueue
&&
545 ThreadQueue
->CaptureWindow
!= Window
->hSelf
)
547 /* only send WM_NCHITTEST messages if we're not capturing the window! */
548 *HitTest
= co_IntSendMessage(Window
->hSelf
, WM_NCHITTEST
, 0,
549 MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
));
551 if (*HitTest
== (USHORT
)HTTRANSPARENT
)
553 PWINDOW_OBJECT DesktopWindow
;
554 HWND hDesktop
= IntGetDesktopWindow();
556 if ((DesktopWindow
= UserGetWindowObject(hDesktop
)))
560 UserRefObjectCo(DesktopWindow
, &DesktopRef
);
562 co_WinPosWindowFromPoint(DesktopWindow
, Window
->pti
->MessageQueue
, &Msg
->pt
, &Wnd
);
567 /* post the message to the other window */
568 Msg
->hwnd
= Wnd
->hSelf
;
569 if(!(Wnd
->state
& WINDOWSTATUS_DESTROYING
))
571 MsqPostMessage(Wnd
->pti
->MessageQueue
, Msg
, FALSE
,
572 Msg
->message
== WM_MOUSEMOVE
? QS_MOUSEMOVE
:
576 /* eat the message */
577 UserDereferenceObject(Wnd
);
578 UserDerefObjectCo(DesktopWindow
);
579 UserDerefObjectCo(Window
);
582 UserDereferenceObject(Wnd
);
585 UserDerefObjectCo(DesktopWindow
);
594 if ( gspv
.bMouseClickLock
&&
595 ( (Msg
->message
== WM_LBUTTONUP
) ||
596 (Msg
->message
== WM_LBUTTONDOWN
) ) )
598 if (MsqIsClkLck(Msg
, Remove
))
600 // FIXME: drop the message, hack: use WM_NULL
601 Msg
->message
= WM_NULL
;
605 if (IS_BTN_MESSAGE(Msg
->message
, DOWN
))
607 /* generate double click messages, if necessary */
608 if ((((*HitTest
) != HTCLIENT
) ||
609 (Window
->Wnd
->pcls
->style
& CS_DBLCLKS
)) &&
610 MsqIsDblClk(Msg
, Remove
))
612 Msg
->message
+= WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
;
616 if(Msg
->message
!= WM_MOUSEWHEEL
)
619 if ((*HitTest
) != HTCLIENT
)
621 Msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
622 if ( (Msg
->message
== WM_NCRBUTTONUP
) &&
623 (((*HitTest
) == HTCAPTION
) || ((*HitTest
) == HTSYSMENU
)) )
625 Msg
->message
= WM_CONTEXTMENU
;
626 Msg
->wParam
= (WPARAM
)Window
->hSelf
;
630 Msg
->wParam
= *HitTest
;
632 Msg
->lParam
= MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
);
634 else if ( ThreadQueue
->MoveSize
== NULL
&&
635 ThreadQueue
->MenuOwner
== NULL
)
637 /* NOTE: Msg->pt should remain in screen coordinates. -- FiN */
638 Msg
->lParam
= MAKELONG(
639 Msg
->pt
.x
- (WORD
)Window
->Wnd
->rcClient
.left
,
640 Msg
->pt
.y
- (WORD
)Window
->Wnd
->rcClient
.top
);
644 UserDerefObjectCo(Window
);
649 * Internal version of PeekMessage() doing all the work
652 co_IntPeekMessage( PUSER_MESSAGE Msg
,
653 PWINDOW_OBJECT Window
,
659 LARGE_INTEGER LargeTickCount
;
660 PUSER_MESSAGE_QUEUE ThreadQueue
;
661 PUSER_MESSAGE Message
;
662 BOOL Present
, RemoveMessages
;
663 USER_REFERENCE_ENTRY Ref
;
665 MOUSEHOOKSTRUCT MHook
;
667 /* The queues and order in which they are checked are documented in the MSDN
668 article on GetMessage() */
670 pti
= PsGetCurrentThreadWin32Thread();
671 ThreadQueue
= pti
->MessageQueue
;
673 /* Inspect RemoveMsg flags */
675 The only flag we process is PM_REMOVE.
676 Processing (High word) PM_QS_Xx Is needed. This and MsgFilterXxx can result
677 with QS_Xx flags to be used to isolate which message check to test for.
678 ATM, we look at all messages and the filters are sent to co_MsqFindMessage
679 and there, it is cross checked.
680 Example: Wine server/queue.c is_keyboard_msg, check_msg_filter and
681 filter_contains_hw_range.
683 RemoveMessages
= RemoveMsg
& PM_REMOVE
;
686 If no filter is specified, messages are processed in the following order:
690 * Input (hardware) messages and system internal events
691 * Sent messages (again)
699 KeQueryTickCount(&LargeTickCount
);
700 ThreadQueue
->LastMsgRead
= LargeTickCount
.u
.LowPart
;
702 /* Dispatch sent messages here. */
703 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
706 /* Now look for a quit message. */
708 if (ThreadQueue
->QuitPosted
)
710 /* According to the PSDK, WM_QUIT messages are always returned, regardless
711 of the filter specified */
712 Msg
->Msg
.hwnd
= NULL
;
713 Msg
->Msg
.message
= WM_QUIT
;
714 Msg
->Msg
.wParam
= ThreadQueue
->QuitExitCode
;
716 Msg
->FreeLParam
= FALSE
;
719 ThreadQueue
->QuitPosted
= FALSE
;
724 /* Now check for normal messages. */
725 Present
= co_MsqFindMessage( ThreadQueue
,
734 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
737 MsqDestroyMessage(Message
);
742 /* Check for hardware events. */
743 Present
= co_MsqFindMessage( ThreadQueue
,
752 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
755 MsqDestroyMessage(Message
);
760 /* Check for sent messages again. */
761 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
764 /* Check for paint messages. */
765 if ( IntGetPaintMessage( Window
,
772 Msg
->FreeLParam
= FALSE
;
776 if (ThreadQueue
->WakeMask
& QS_TIMER
)
777 if (PostTimerMessages(Window
)) // If there are timers ready,
778 goto CheckMessages
; // go back and process them.
780 // LOL! Polling Timer Queue? How much time is spent doing this?
781 /* Check for WM_(SYS)TIMER messages */
782 Present
= MsqGetTimerMessage( ThreadQueue
,
790 Msg
->FreeLParam
= FALSE
;
800 PWINDOW_OBJECT MsgWindow
= NULL
;
802 /* Mouse message process */
805 ( MsgWindow
= UserGetWindowObject(Msg
->Msg
.hwnd
) ) &&
806 Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
807 Msg
->Msg
.message
<= WM_MOUSELAST
)
811 UserRefObjectCo(MsgWindow
, &Ref
);
813 if ( co_IntTranslateMouseMessage( ThreadQueue
,
817 /* FIXME - check message filter again, if the message doesn't match anymore,
820 UserDerefObjectCo(MsgWindow
);
821 /* eat the message, search again */
825 if(ThreadQueue
->CaptureWindow
== NULL
)
827 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
829 if ( ( Msg
->Msg
.message
!= WM_MOUSEMOVE
&&
830 Msg
->Msg
.message
!= WM_NCMOUSEMOVE
) &&
831 IS_BTN_MESSAGE(Msg
->Msg
.message
, DOWN
) &&
832 co_IntActivateWindowMouse(ThreadQueue
, &Msg
->Msg
, MsgWindow
, &HitTest
) )
834 UserDerefObjectCo(MsgWindow
);
835 /* eat the message, search again */
840 UserDerefObjectCo(MsgWindow
);
844 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
849 // UserDereferenceObject(MsgWindow);
855 if ( ( Msg
->Msg
.hwnd
&&
856 Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
857 Msg
->Msg
.message
<= WM_MOUSELAST
) &&
858 co_IntTranslateMouseMessage( ThreadQueue
,
862 /* FIXME - check message filter again, if the message doesn't match anymore,
865 /* eat the message, search again */
870 if ( ISITHOOKED(WH_MOUSE
) &&
871 Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
872 Msg
->Msg
.message
<= WM_MOUSELAST
)
874 MHook
.pt
= Msg
->Msg
.pt
;
875 MHook
.hwnd
= Msg
->Msg
.hwnd
;
876 MHook
.wHitTestCode
= HitTest
;
877 MHook
.dwExtraInfo
= 0;
878 if (co_HOOK_CallHooks( WH_MOUSE
,
879 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
883 if (ISITHOOKED(WH_CBT
))
885 MHook
.pt
= Msg
->Msg
.pt
;
886 MHook
.hwnd
= Msg
->Msg
.hwnd
;
887 MHook
.wHitTestCode
= HitTest
;
888 MHook
.dwExtraInfo
= 0;
889 co_HOOK_CallHooks( WH_CBT
,
898 if ( ISITHOOKED(WH_KEYBOARD
) &&
899 (Msg
->Msg
.message
== WM_KEYDOWN
|| Msg
->Msg
.message
== WM_KEYUP
) )
901 if (co_HOOK_CallHooks( WH_KEYBOARD
,
902 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
903 LOWORD(Msg
->Msg
.wParam
),
906 if (ISITHOOKED(WH_CBT
))
908 /* skip this message */
909 co_HOOK_CallHooks( WH_CBT
,
911 LOWORD(Msg
->Msg
.wParam
),
917 // The WH_GETMESSAGE hook enables an application to monitor messages about to
918 // be returned by the GetMessage or PeekMessage function.
919 if (ISITHOOKED(WH_GETMESSAGE
))
921 //DPRINT1("Peek WH_GETMESSAGE -> %x\n",&Msg);
922 co_HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, RemoveMsg
& PM_REMOVE
, (LPARAM
)&Msg
->Msg
);
930 static NTSTATUS FASTCALL
931 CopyMsgToKernelMem(MSG
*KernelModeMsg
, MSG
*UserModeMsg
, PMSGMEMORY MsgMemoryEntry
)
938 *KernelModeMsg
= *UserModeMsg
;
940 /* See if this message type is present in the table */
941 if (NULL
== MsgMemoryEntry
)
943 /* Not present, no copying needed */
944 return STATUS_SUCCESS
;
947 /* Determine required size */
948 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
952 /* Allocate kernel mem */
953 KernelMem
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
954 if (NULL
== KernelMem
)
956 DPRINT1("Not enough memory to copy message to kernel mem\n");
957 return STATUS_NO_MEMORY
;
959 KernelModeMsg
->lParam
= (LPARAM
) KernelMem
;
961 /* Copy data if required */
962 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_READ
))
964 Status
= MmCopyFromCaller(KernelMem
, (PVOID
) UserModeMsg
->lParam
, Size
);
965 if (! NT_SUCCESS(Status
))
967 DPRINT1("Failed to copy message to kernel: invalid usermode buffer\n");
968 ExFreePoolWithTag(KernelMem
, TAG_MSG
);
974 /* Make sure we don't pass any secrets to usermode */
975 RtlZeroMemory(KernelMem
, Size
);
980 KernelModeMsg
->lParam
= 0;
983 return STATUS_SUCCESS
;
986 static NTSTATUS FASTCALL
987 CopyMsgToUserMem(MSG
*UserModeMsg
, MSG
*KernelModeMsg
)
990 PMSGMEMORY MsgMemoryEntry
;
993 /* See if this message type is present in the table */
994 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
->message
);
995 if (NULL
== MsgMemoryEntry
)
997 /* Not present, no copying needed */
998 return STATUS_SUCCESS
;
1001 /* Determine required size */
1002 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
1006 /* Copy data if required */
1007 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_WRITE
))
1009 Status
= MmCopyToCaller((PVOID
) UserModeMsg
->lParam
, (PVOID
) KernelModeMsg
->lParam
, Size
);
1010 if (! NT_SUCCESS(Status
))
1012 DPRINT1("Failed to copy message from kernel: invalid usermode buffer\n");
1013 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1018 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1021 return STATUS_SUCCESS
;
1024 static BOOL FASTCALL
1025 co_IntWaitMessage( PWINDOW_OBJECT Window
,
1030 PUSER_MESSAGE_QUEUE ThreadQueue
;
1031 NTSTATUS Status
= STATUS_SUCCESS
;
1034 pti
= PsGetCurrentThreadWin32Thread();
1035 ThreadQueue
= pti
->MessageQueue
;
1039 if ( co_IntPeekMessage( &Msg
,
1047 /* Nothing found. Wait for new messages. */
1048 Status
= co_MsqWaitForNewMessages( ThreadQueue
,
1053 while ( (STATUS_WAIT_0
<= Status
&& Status
<= STATUS_WAIT_63
) ||
1054 STATUS_TIMEOUT
== Status
);
1056 SetLastNtError(Status
);
1058 DPRINT1("Exit co_IntWaitMessage on error!\n");
1064 co_IntGetPeekMessage( PMSG pMsg
,
1072 PWINDOW_OBJECT Window
;
1075 if ( hWnd
== HWND_TOPMOST
||
1076 hWnd
== HWND_BROADCAST
)
1079 /* Validate input */
1080 if (hWnd
&& hWnd
!= HWND_BOTTOM
)
1082 if (!(Window
= UserGetWindowObject(hWnd
)))
1092 Window
= (PWINDOW_OBJECT
)hWnd
;
1095 if (MsgFilterMax
< MsgFilterMin
)
1103 Present
= co_IntPeekMessage( &Msg
,
1110 RtlCopyMemory( pMsg
, &Msg
.Msg
, sizeof(MSG
));
1113 return (WM_QUIT
!= pMsg
->message
);
1118 if ( bGMSG
&& !co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
) )
1124 if (!(RemoveMsg
& PM_NOYIELD
))
1126 // Yield this thread!
1129 UserEnterExclusive();
1130 // Fall through to fail.
1134 while( bGMSG
&& !Present
);
1140 UserPostThreadMessage( DWORD idThread
,
1147 PTHREADINFO pThread
;
1148 LARGE_INTEGER LargeTickCount
;
1151 DPRINT1("UserPostThreadMessage wParam 0x%x lParam 0x%x\n", wParam
,lParam
);
1153 if (FindMsgMemory(Msg
) != 0)
1155 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1159 Status
= PsLookupThreadByThreadId((HANDLE
)idThread
,&peThread
);
1161 if( Status
== STATUS_SUCCESS
)
1163 pThread
= (PTHREADINFO
)peThread
->Tcb
.Win32Thread
;
1165 !pThread
->MessageQueue
||
1166 (pThread
->TIF_flags
& TIF_INCLEANUP
))
1168 ObDereferenceObject( peThread
);
1172 Message
.hwnd
= NULL
;
1173 Message
.message
= Msg
;
1174 Message
.wParam
= wParam
;
1175 Message
.lParam
= lParam
;
1176 Message
.pt
= gpsi
->ptCursor
;
1178 KeQueryTickCount(&LargeTickCount
);
1179 pThread
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1180 MsqPostMessage(pThread
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1181 ObDereferenceObject( peThread
);
1186 SetLastNtError( Status
);
1192 UserPostMessage( HWND Wnd
,
1199 LARGE_INTEGER LargeTickCount
;
1201 if (FindMsgMemory(Msg
) != 0)
1203 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1208 return UserPostThreadMessage( PtrToInt(PsGetCurrentThreadId()),
1213 if (Wnd
== HWND_BROADCAST
)
1216 PWINDOW_OBJECT DesktopWindow
;
1219 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1220 List
= IntWinListChildren(DesktopWindow
);
1224 for (i
= 0; List
[i
]; i
++)
1225 UserPostMessage(List
[i
], Msg
, wParam
, lParam
);
1231 PWINDOW_OBJECT Window
;
1233 Window
= UserGetWindowObject(Wnd
);
1234 if ( !Window
|| !Window
->Wnd
)
1239 pti
= Window
->Wnd
->head
.pti
;
1240 if ( pti
->TIF_flags
& TIF_INCLEANUP
)
1242 DPRINT1("Attempted to post message to window 0x%x when the thread is in cleanup!\n", Wnd
);
1246 if ( Window
->state
& WINDOWSTATUS_DESTROYING
)
1248 DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd
);
1249 /* FIXME - last error code? */
1255 MsqPostQuitMessage(Window
->pti
->MessageQueue
, wParam
);
1260 Message
.message
= Msg
;
1261 Message
.wParam
= wParam
;
1262 Message
.lParam
= lParam
;
1263 Message
.pt
= gpsi
->ptCursor
;
1264 KeQueryTickCount(&LargeTickCount
);
1265 pti
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1266 MsqPostMessage(Window
->pti
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1274 co_IntSendMessage( HWND hWnd
,
1279 ULONG_PTR Result
= 0;
1280 if(co_IntSendMessageTimeout(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
))
1282 return (LRESULT
)Result
;
1289 co_IntSendMessageTimeoutSingle( HWND hWnd
,
1295 ULONG_PTR
*uResult
)
1299 PWINDOW_OBJECT Window
= NULL
;
1300 PMSGMEMORY MsgMemoryEntry
;
1301 INT lParamBufferSize
;
1302 LPARAM lParamPacked
;
1303 PTHREADINFO Win32Thread
;
1304 DECLARE_RETURN(LRESULT
);
1305 USER_REFERENCE_ENTRY Ref
;
1307 if (!(Window
= UserGetWindowObject(hWnd
)))
1312 UserRefObjectCo(Window
, &Ref
);
1314 Win32Thread
= PsGetCurrentThreadWin32Thread();
1316 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1318 if ( NULL
!= Win32Thread
&&
1319 Window
->pti
->MessageQueue
== Win32Thread
->MessageQueue
)
1321 if (Win32Thread
->TIF_flags
& TIF_INCLEANUP
)
1323 /* Never send messages to exiting threads */
1327 /* See if this message type is present in the table */
1328 MsgMemoryEntry
= FindMsgMemory(Msg
);
1329 if (NULL
== MsgMemoryEntry
)
1331 lParamBufferSize
= -1;
1335 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1338 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
)))
1340 DPRINT1("Failed to pack message parameters\n");
1344 Result
= (ULONG_PTR
)co_IntCallWindowProc( Window
->Wnd
->lpfnWndProc
,
1345 !Window
->Wnd
->Unicode
,
1356 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1358 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
)))
1360 DPRINT1("Failed to unpack message parameters\n");
1367 if (uFlags
& SMTO_ABORTIFHUNG
&& MsqIsHung(Window
->pti
->MessageQueue
))
1369 /* FIXME - Set a LastError? */
1373 if (Window
->state
& WINDOWSTATUS_DESTROYING
)
1375 /* FIXME - last error? */
1376 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1382 Status
= co_MsqSendMessage( Window
->pti
->MessageQueue
,
1388 (uFlags
& SMTO_BLOCK
),
1392 while ((STATUS_TIMEOUT
== Status
) &&
1393 (uFlags
& SMTO_NOTIMEOUTIFNOTHUNG
) &&
1394 !MsqIsHung(Window
->pti
->MessageQueue
));
1396 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1398 if (STATUS_TIMEOUT
== Status
)
1402 Microsoft Windows 2000: If GetLastError returns zero, then the function
1404 XP+ : If the function fails or times out, the return value is zero.
1405 To get extended error information, call GetLastError. If GetLastError
1406 returns ERROR_TIMEOUT, then the function timed out.
1408 SetLastWin32Error(ERROR_TIMEOUT
);
1411 else if (! NT_SUCCESS(Status
))
1413 SetLastNtError(Status
);
1420 if (Window
) UserDerefObjectCo(Window
);
1425 co_IntSendMessageTimeout( HWND hWnd
,
1431 ULONG_PTR
*uResult
)
1433 PWINDOW_OBJECT DesktopWindow
;
1437 if (HWND_BROADCAST
!= hWnd
)
1439 return co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1442 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1443 if (NULL
== DesktopWindow
)
1445 SetLastWin32Error(ERROR_INTERNAL_ERROR
);
1449 Children
= IntWinListChildren(DesktopWindow
);
1450 if (NULL
== Children
)
1455 for (Child
= Children
; NULL
!= *Child
; Child
++)
1457 co_IntSendMessageTimeoutSingle(*Child
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1460 ExFreePool(Children
);
1462 return (LRESULT
) TRUE
;
1466 /* This function posts a message if the destination's message queue belongs to
1467 another thread, otherwise it sends the message. It does not support broadcast
1470 co_IntPostOrSendMessage( HWND hWnd
,
1477 PWINDOW_OBJECT Window
;
1479 if ( hWnd
== HWND_BROADCAST
)
1484 if(!(Window
= UserGetWindowObject(hWnd
)))
1489 pti
= PsGetCurrentThreadWin32Thread();
1491 if ( Window
->pti
->MessageQueue
!= pti
->MessageQueue
&&
1492 FindMsgMemory(Msg
) == 0 )
1494 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1498 if ( !co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
) )
1504 return (LRESULT
)Result
;
1508 co_IntDoSendMessage( HWND hWnd
,
1513 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1516 LRESULT Result
= TRUE
;
1518 PWINDOW_OBJECT Window
= NULL
;
1519 NTUSERSENDMESSAGEINFO Info
;
1522 PMSGMEMORY MsgMemoryEntry
;
1524 RtlZeroMemory(&Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1526 /* FIXME: Call hooks. */
1527 if (HWND_BROADCAST
!= hWnd
)
1529 Window
= UserGetWindowObject(hWnd
);
1530 if ( !Window
|| !Window
->Wnd
)
1532 /* Tell usermode to not touch this one */
1533 Info
.HandledByKernel
= TRUE
;
1534 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1539 /* Check for an exiting window. */
1540 if (Window
&& Window
->state
& WINDOWSTATUS_DESTROYING
)
1542 DPRINT1("co_IntDoSendMessage Window Exiting!\n");
1545 /* See if the current thread can handle the message */
1546 pti
= PsGetCurrentThreadWin32Thread();
1548 // This is checked in user mode!!!!!!!
1549 if ( HWND_BROADCAST
!= hWnd
&&
1551 Window
->pti
->MessageQueue
== pti
->MessageQueue
&&
1552 !ISITHOOKED(WH_CALLWNDPROC
) &&
1553 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
1554 ( Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
) )
1556 /* Gather the information usermode needs to call the window proc directly */
1557 Info
.HandledByKernel
= FALSE
;
1559 Status
= MmCopyFromCaller(&(Info
.Ansi
), &(UnsafeInfo
->Ansi
),
1561 if (! NT_SUCCESS(Status
))
1563 Info
.Ansi
= ! Window
->Wnd
->Unicode
;
1566 Info
.Ansi
= !Window
->Wnd
->Unicode
;
1567 Info
.Proc
= Window
->Wnd
->lpfnWndProc
;
1571 /* Must be handled by other thread */
1572 // if (HWND_BROADCAST != hWnd)
1574 // UserDereferenceObject(Window);
1576 Info
.HandledByKernel
= TRUE
;
1577 UserModeMsg
.hwnd
= hWnd
;
1578 UserModeMsg
.message
= Msg
;
1579 UserModeMsg
.wParam
= wParam
;
1580 UserModeMsg
.lParam
= lParam
;
1581 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1583 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1584 if (! NT_SUCCESS(Status
))
1586 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1587 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1588 return (dsm
? 0 : -1);
1593 Result
= co_IntSendMessage( KernelModeMsg
.hwnd
,
1594 KernelModeMsg
.message
,
1595 KernelModeMsg
.wParam
,
1596 KernelModeMsg
.lParam
);
1600 Result
= co_IntSendMessageTimeout( KernelModeMsg
.hwnd
,
1601 KernelModeMsg
.message
,
1602 KernelModeMsg
.wParam
,
1603 KernelModeMsg
.lParam
,
1609 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1610 if (! NT_SUCCESS(Status
))
1612 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1613 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1614 return(dsm
? 0 : -1);
1618 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1619 if (! NT_SUCCESS(Status
))
1621 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1624 return (LRESULT
)Result
;
1629 UserSendNotifyMessage( HWND hWnd
,
1636 if (FindMsgMemory(Msg
) != 0)
1638 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1642 // Basicly the same as IntPostOrSendMessage
1643 if (hWnd
== HWND_BROADCAST
) //Handle Broadcast
1646 PWINDOW_OBJECT DesktopWindow
;
1649 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1650 List
= IntWinListChildren(DesktopWindow
);
1654 for (i
= 0; List
[i
]; i
++)
1656 UserSendNotifyMessage(List
[i
], Msg
, wParam
, lParam
);
1665 PWINDOW_OBJECT Window
;
1668 if ( !(Window
= UserGetWindowObject(hWnd
)) ) return FALSE
;
1670 pti
= PsGetCurrentThreadWin32Thread();
1672 if (Window
->pti
->MessageQueue
!= pti
->MessageQueue
)
1673 { // Send message w/o waiting for it.
1674 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1677 { // Handle message and callback.
1678 Message
.hwnd
= hWnd
;
1679 Message
.message
= Msg
;
1680 Message
.wParam
= wParam
;
1681 Message
.lParam
= lParam
;
1683 Result
= co_IntSendMessageTimeoutSingle( hWnd
,
1697 IntGetQueueStatus(BOOL ClearChanges
)
1700 PUSER_MESSAGE_QUEUE Queue
;
1702 DECLARE_RETURN(DWORD
);
1704 DPRINT("Enter IntGetQueueStatus\n");
1706 pti
= PsGetCurrentThreadWin32Thread();
1707 Queue
= pti
->MessageQueue
;
1709 Result
= MAKELONG(Queue
->QueueBits
, Queue
->ChangedBits
);
1712 Queue
->ChangedBits
= 0;
1718 DPRINT("Leave IntGetQueueStatus, ret=%i\n",_ret_
);
1723 IntInitMessagePumpHook()
1725 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1727 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
++;
1734 IntUninitMessagePumpHook()
1736 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1738 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
<= 0)
1742 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
--;
1748 /** Functions ******************************************************************/
1751 NtUserPostMessage(HWND hWnd
,
1756 DECLARE_RETURN(BOOL
);
1758 DPRINT("Enter NtUserPostMessage\n");
1759 UserEnterExclusive();
1761 RETURN( UserPostMessage(hWnd
, Msg
, wParam
, lParam
));
1764 DPRINT("Leave NtUserPostMessage, ret=%i\n",_ret_
);
1770 NtUserPostThreadMessage(DWORD idThread
,
1775 DECLARE_RETURN(BOOL
);
1777 DPRINT("Enter NtUserPostThreadMessage\n");
1778 UserEnterExclusive();
1780 RETURN( UserPostThreadMessage( idThread
,
1786 DPRINT("Leave NtUserPostThreadMessage, ret=%i\n",_ret_
);
1792 NtUserQuerySendMessage(DWORD Unknown0
)
1800 ////////// API on the way out!
1802 NtUserSendMessageTimeout( HWND hWnd
,
1809 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1813 DECLARE_RETURN(BOOL
);
1815 DPRINT("Enter NtUserSendMessageTimeout\n");
1816 UserEnterExclusive();
1818 dsm
.uFlags
= uFlags
;
1819 dsm
.uTimeout
= uTimeout
;
1820 Result
= co_IntDoSendMessage(hWnd
, Msg
, wParam
, lParam
, &dsm
, UnsafeInfo
);
1821 if(uResult
!= NULL
&& Result
!= 0)
1825 Status
= MmCopyToCaller(uResult
, &dsm
.Result
, sizeof(ULONG_PTR
));
1826 if(!NT_SUCCESS(Status
))
1828 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1835 DPRINT("Leave NtUserSendMessageTimeout, ret=%i\n",_ret_
);
1841 NtUserSendMessage( HWND Wnd
,
1845 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1847 DECLARE_RETURN(BOOL
);
1849 DPRINT("Enter NtUserSendMessage\n");
1850 UserEnterExclusive();
1852 RETURN(co_IntDoSendMessage(Wnd
, Msg
, wParam
, lParam
, NULL
, UnsafeInfo
));
1855 DPRINT("Leave NtUserSendMessage, ret=%i\n",_ret_
);
1862 NtUserWaitMessage(VOID
)
1864 DECLARE_RETURN(BOOL
);
1866 DPRINT("EnterNtUserWaitMessage\n");
1867 UserEnterExclusive();
1869 RETURN(co_IntWaitMessage(NULL
, 0, 0));
1872 DPRINT("Leave NtUserWaitMessage, ret=%i\n",_ret_
);
1879 NtUserGetMessage( PNTUSERGETMESSAGEINFO UnsafeInfo
,
1884 * FUNCTION: Get a message from the calling thread's message queue.
1886 * UnsafeMsg - Pointer to the structure which receives the returned message.
1887 * Wnd - Window whose messages are to be retrieved.
1888 * MsgFilterMin - Integer value of the lowest message value to be
1890 * MsgFilterMax - Integer value of the highest message value to be
1895 NTUSERGETMESSAGEINFO Info
;
1897 /* FIXME: if initialization is removed, gcc complains that this may be used before initialization. Please review */
1898 PWINDOW_OBJECT Window
= NULL
;
1899 PMSGMEMORY MsgMemoryEntry
;
1903 DECLARE_RETURN(BOOL
);
1904 // USER_REFERENCE_ENTRY Ref;
1906 DPRINT("Enter NtUserGetMessage\n");
1907 UserEnterExclusive();
1909 /* Validate input */
1910 if (hWnd
&& !(Window
= UserGetWindowObject(hWnd
)))
1915 // if (Window) UserRefObjectCo(Window, &Ref);
1917 if (MsgFilterMax
< MsgFilterMin
)
1925 GotMessage
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
);
1929 /* See if this message type is present in the table */
1930 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
1931 if (NULL
== MsgMemoryEntry
)
1933 /* Not present, no copying needed */
1934 Info
.LParamSize
= 0;
1938 /* Determine required size */
1939 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
1941 /* Allocate required amount of user-mode memory */
1942 Info
.LParamSize
= Size
;
1944 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
1945 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
1947 if (! NT_SUCCESS(Status
))
1949 SetLastNtError(Status
);
1952 /* Transfer lParam data to user-mode mem */
1953 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
1954 if (! NT_SUCCESS(Status
))
1956 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
1957 &Info
.LParamSize
, MEM_DECOMMIT
);
1958 SetLastNtError(Status
);
1961 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
1963 if (Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
1965 ExFreePool((void *) Msg
.Msg
.lParam
);
1967 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
1968 if (! NT_SUCCESS(Status
))
1970 SetLastNtError(Status
);
1974 else if (! co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
))
1979 while (! GotMessage
);
1981 RETURN( WM_QUIT
!= Info
.Msg
.message
);
1984 // if (Window) UserDerefObjectCo(Window);
1986 DPRINT("Leave NtUserGetMessage\n");
2002 DECLARE_RETURN(BOOL
);
2004 DPRINT("Enter NtUserGetMessage\n");
2005 UserEnterExclusive();
2007 if ( (MsgFilterMin
|MsgFilterMax
) & ~WM_MAXIMUM
)
2009 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2013 RtlZeroMemory(&Msg
, sizeof(MSG
));
2015 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
, TRUE
);
2021 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
2022 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
2024 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2026 SetLastNtError(_SEH2_GetExceptionCode());
2034 DPRINT("Leave NtUserGetMessage\n");
2040 NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
2048 NTUSERGETMESSAGEINFO Info
;
2049 PWINDOW_OBJECT Window
;
2050 PMSGMEMORY MsgMemoryEntry
;
2054 DECLARE_RETURN(BOOL
);
2056 DPRINT("Enter NtUserPeekMessage\n");
2057 UserEnterExclusive();
2059 if (hWnd
== (HWND
)-1 || hWnd
== (HWND
)0x0000FFFF || hWnd
== (HWND
)0xFFFFFFFF)
2062 /* Validate input */
2063 if (hWnd
&& hWnd
!= (HWND
)1)
2065 if (!(Window
= UserGetWindowObject(hWnd
)))
2072 Window
= (PWINDOW_OBJECT
)hWnd
;
2075 if (MsgFilterMax
< MsgFilterMin
)
2081 Present
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
);
2086 /* See if this message type is present in the table */
2087 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
2088 if (NULL
== MsgMemoryEntry
)
2090 /* Not present, no copying needed */
2091 Info
.LParamSize
= 0;
2095 /* Determine required size */
2096 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
2098 /* Allocate required amount of user-mode memory */
2099 Info
.LParamSize
= Size
;
2101 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
2102 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
2103 if (! NT_SUCCESS(Status
))
2105 SetLastNtError(Status
);
2108 /* Transfer lParam data to user-mode mem */
2109 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
2110 if (! NT_SUCCESS(Status
))
2112 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
2113 &Info
.LParamSize
, MEM_RELEASE
);
2114 SetLastNtError(Status
);
2117 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
2119 if (RemoveMsg
&& Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
2121 ExFreePool((void *) Msg
.Msg
.lParam
);
2123 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
2124 if (! NT_SUCCESS(Status
))
2126 SetLastNtError(Status
);
2134 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2150 DECLARE_RETURN(BOOL
);
2152 DPRINT("Enter NtUserPeekMessage\n");
2153 UserEnterExclusive();
2155 if ( RemoveMsg
& PM_BADMSGFLAGS
)
2157 SetLastWin32Error(ERROR_INVALID_FLAGS
);
2161 RtlZeroMemory(&Msg
, sizeof(MSG
));
2163 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
, FALSE
);
2169 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
2170 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
2172 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2174 SetLastNtError(_SEH2_GetExceptionCode());
2182 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2189 NtUserCallMsgFilter(
2193 BOOL BadChk
= FALSE
, Ret
= FALSE
;
2195 DECLARE_RETURN(BOOL
);
2197 DPRINT("Enter NtUserCallMsgFilter\n");
2198 UserEnterExclusive();
2203 ProbeForRead((PVOID
)lpmsg
,
2206 RtlCopyMemory( &Msg
,
2210 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2219 if (BadChk
) RETURN( FALSE
);
2221 if ( ISITHOOKED(WH_SYSMSGFILTER
) &&
2222 co_HOOK_CallHooks( WH_SYSMSGFILTER
, code
, 0, (LPARAM
)&Msg
))
2228 if ( ISITHOOKED(WH_MSGFILTER
) )
2230 Ret
= co_HOOK_CallHooks( WH_MSGFILTER
, code
, 0, (LPARAM
)&Msg
);
2236 ProbeForWrite((PVOID
)lpmsg
,
2239 RtlCopyMemory((PVOID
)lpmsg
,
2243 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2248 if (BadChk
) RETURN( FALSE
);
2252 DPRINT("Leave NtUserCallMsgFilter. ret=%i\n", _ret_
);
2258 NtUserDispatchMessage(PMSG UnsafeMsgInfo
)
2264 UserEnterExclusive();
2267 ProbeForRead(UnsafeMsgInfo
, sizeof(MSG
), 1);
2268 RtlCopyMemory(&SafeMsg
, UnsafeMsgInfo
, sizeof(MSG
));
2270 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2272 SetLastNtError(_SEH2_GetExceptionCode());
2277 if (!Hit
) Res
= IntDispatchMessage(&SafeMsg
);
2285 NtUserTranslateMessage(LPMSG lpMsg
,
2290 DECLARE_RETURN(BOOL
);
2292 DPRINT("Enter NtUserTranslateMessage\n");
2293 UserEnterExclusive();
2295 Status
= MmCopyFromCaller(&SafeMsg
, lpMsg
, sizeof(MSG
));
2296 if(!NT_SUCCESS(Status
))
2298 SetLastNtError(Status
);
2302 RETURN( IntTranslateKbdMessage(&SafeMsg
, dwhkl
));
2305 DPRINT("Leave NtUserTranslateMessage: ret=%i\n",_ret_
);
2316 ULONG_PTR ResultInfo
,
2317 DWORD dwType
, // fnID?
2320 LRESULT lResult
= 0;
2322 BOOL BadChk
= FALSE
;
2323 PWINDOW_OBJECT Window
= NULL
;
2324 USER_REFERENCE_ENTRY Ref
;
2326 UserEnterExclusive();
2328 /* Validate input */
2329 if (hWnd
&& (hWnd
!= INVALID_HANDLE_VALUE
) && !(Window
= UserGetWindowObject(hWnd
)))
2336 case FNID_DEFWINDOWPROC
:
2337 UserRefObjectCo(Window
, &Ref
);
2338 lResult
= IntDefWindowProc(Window
, Msg
, wParam
, lParam
, Ansi
);
2340 UserDerefObjectCo(Window
);
2342 case FNID_SENDNOTIFYMESSAGE
:
2343 Ret
= UserSendNotifyMessage(hWnd
, Msg
, wParam
, lParam
);
2345 case FNID_BROADCASTSYSTEMMESSAGE
:
2348 DWORD_PTR RetVal
= 0;
2354 ProbeForWrite((PVOID
)ResultInfo
,
2355 sizeof(BROADCASTPARM
),
2357 RtlCopyMemory(&parm
, (PVOID
)ResultInfo
, sizeof(BROADCASTPARM
));
2359 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2369 if ( parm
.recipients
& BSM_ALLDESKTOPS
||
2370 parm
.recipients
== BSM_ALLCOMPONENTS
)
2373 else if (parm
.recipients
& BSM_APPLICATIONS
)
2375 if (parm
.flags
& BSF_QUERY
)
2377 if (parm
.flags
& BSF_FORCEIFHUNG
|| parm
.flags
& BSF_NOHANG
)
2379 co_IntSendMessageTimeout( HWND_BROADCAST
,
2387 else if (parm
.flags
& BSF_NOTIMEOUTIFNOTHUNG
)
2389 co_IntSendMessageTimeout( HWND_BROADCAST
,
2393 SMTO_NOTIMEOUTIFNOTHUNG
,
2399 co_IntSendMessageTimeout( HWND_BROADCAST
,
2408 else if (parm
.flags
& BSF_POSTMESSAGE
)
2410 Ret
= UserPostMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2412 else if ( parm
.flags
& BSF_SENDNOTIFYMESSAGE
)
2414 Ret
= UserSendNotifyMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2419 case FNID_SENDMESSAGECALLBACK
:
2421 // CallNextHook bypass.
2422 case FNID_CALLWNDPROC
:
2423 case FNID_CALLWNDPROCRET
:
2425 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
2426 PHOOK NextObj
, Hook
= ClientInfo
->phkCurrent
;
2428 if (!ClientInfo
|| !Hook
) break;
2430 UserReferenceObject(Hook
);
2432 if (Hook
->Thread
&& (Hook
->Thread
!= PsGetCurrentThread()))
2434 UserDereferenceObject(Hook
);
2438 NextObj
= IntGetNextHook(Hook
);
2439 ClientInfo
->phkCurrent
= NextObj
;
2441 if ( Hook
->HookId
== WH_CALLWNDPROC
)
2446 CWP
.wParam
= wParam
;
2447 CWP
.lParam
= lParam
;
2448 DPRINT("WH_CALLWNDPROC: Hook %x NextHook %x\n", Hook
, NextObj
);
2450 lResult
= co_IntCallHookProc( Hook
->HookId
,
2452 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2463 CWPR
.wParam
= wParam
;
2464 CWPR
.lParam
= lParam
;
2465 CWPR
.lResult
= ClientInfo
->dwHookData
;
2467 lResult
= co_IntCallHookProc( Hook
->HookId
,
2469 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2475 UserDereferenceObject(Hook
);
2476 lResult
= (LRESULT
) NextObj
;
2483 case FNID_DEFWINDOWPROC
:
2484 case FNID_CALLWNDPROC
:
2485 case FNID_CALLWNDPROCRET
:
2490 ProbeForWrite((PVOID
)ResultInfo
, sizeof(LRESULT
), 1);
2491 RtlCopyMemory((PVOID
)ResultInfo
, &lResult
, sizeof(LRESULT
));
2493 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2506 return BadChk
? FALSE
: Ret
;
2509 #define INFINITE 0xFFFFFFFF
2510 #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
2514 NtUserWaitForInputIdle(
2516 IN DWORD dwMilliseconds
,
2520 PPROCESSINFO W32Process
;
2523 LARGE_INTEGER Timeout
;
2524 ULONGLONG StartTime
, Run
, Elapsed
= 0;
2526 UserEnterExclusive();
2528 Status
= ObReferenceObjectByHandle(hProcess
,
2529 PROCESS_QUERY_INFORMATION
,
2535 if (!NT_SUCCESS(Status
))
2538 SetLastNtError(Status
);
2542 W32Process
= (PPROCESSINFO
)Process
->Win32Process
;
2545 ObDereferenceObject(Process
);
2547 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2551 EngCreateEvent((PEVENT
*)&W32Process
->InputIdleEvent
);
2553 Handles
[0] = Process
;
2554 Handles
[1] = W32Process
->InputIdleEvent
;
2558 ObDereferenceObject(Process
);
2560 return STATUS_SUCCESS
; /* no event to wait on */
2563 StartTime
= EngGetTickCount();
2565 Run
= dwMilliseconds
;
2567 DPRINT("WFII: waiting for %p\n", Handles
[1] );
2570 Timeout
.QuadPart
= Run
- Elapsed
;
2572 Status
= KeWaitForMultipleObjects( 2,
2578 dwMilliseconds
== INFINITE
? NULL
: &Timeout
,
2580 UserEnterExclusive();
2582 if (!NT_SUCCESS(Status
))
2584 SetLastNtError(Status
);
2585 Status
= WAIT_FAILED
;
2592 Status
= WAIT_FAILED
;
2598 co_IntPeekMessage( &Msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2602 case STATUS_USER_APC
:
2603 case STATUS_ALERTED
:
2604 case STATUS_TIMEOUT
:
2605 DPRINT1("WFII: timeout\n");
2606 Status
= STATUS_TIMEOUT
;
2610 DPRINT1("WFII: finished\n");
2611 Status
= STATUS_SUCCESS
;
2615 if (dwMilliseconds
!= INFINITE
)
2617 Elapsed
= EngGetTickCount() - StartTime
;
2620 Status
= STATUS_TIMEOUT
;
2627 if (W32Process
->InputIdleEvent
)
2629 EngDeleteEvent((PEVENT
)W32Process
->InputIdleEvent
);
2630 W32Process
->InputIdleEvent
= NULL
;
2632 ObDereferenceObject(Process
);