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
->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
->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
->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 */
674 /* FIXME: The only flag we process is PM_REMOVE - processing of others must still be implemented */
675 RemoveMessages
= RemoveMsg
& PM_REMOVE
;
681 KeQueryTickCount(&LargeTickCount
);
682 ThreadQueue
->LastMsgRead
= LargeTickCount
.u
.LowPart
;
684 /* Dispatch sent messages here. */
685 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
688 /* Now look for a quit message. */
690 if (ThreadQueue
->QuitPosted
)
692 /* According to the PSDK, WM_QUIT messages are always returned, regardless
693 of the filter specified */
694 Msg
->Msg
.hwnd
= NULL
;
695 Msg
->Msg
.message
= WM_QUIT
;
696 Msg
->Msg
.wParam
= ThreadQueue
->QuitExitCode
;
698 Msg
->FreeLParam
= FALSE
;
701 ThreadQueue
->QuitPosted
= FALSE
;
706 /* Now check for normal messages. */
707 Present
= co_MsqFindMessage( ThreadQueue
,
716 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
719 MsqDestroyMessage(Message
);
724 /* Check for hardware events. */
725 Present
= co_MsqFindMessage( ThreadQueue
,
734 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
737 MsqDestroyMessage(Message
);
742 /* Check for sent messages again. */
743 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
746 /* Check for paint messages. */
747 if ( IntGetPaintMessage( Window
,
754 Msg
->FreeLParam
= FALSE
;
758 if (ThreadQueue
->WakeMask
& QS_TIMER
)
759 if (PostTimerMessages(Window
)) // If there are timers ready,
760 goto CheckMessages
; // go back and process them.
762 // LOL! Polling Timer Queue? How much time is spent doing this?
763 /* Check for WM_(SYS)TIMER messages */
764 Present
= MsqGetTimerMessage( ThreadQueue
,
772 Msg
->FreeLParam
= FALSE
;
782 PWINDOW_OBJECT MsgWindow
= NULL
;
784 /* Mouse message process */
787 ( MsgWindow
= UserGetWindowObject(Msg
->Msg
.hwnd
) ) &&
788 Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
789 Msg
->Msg
.message
<= WM_MOUSELAST
)
793 UserRefObjectCo(MsgWindow
, &Ref
);
795 if ( co_IntTranslateMouseMessage( ThreadQueue
,
799 /* FIXME - check message filter again, if the message doesn't match anymore,
802 UserDerefObjectCo(MsgWindow
);
803 /* eat the message, search again */
807 if(ThreadQueue
->CaptureWindow
== NULL
)
809 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
811 if ( ( Msg
->Msg
.message
!= WM_MOUSEMOVE
&&
812 Msg
->Msg
.message
!= WM_NCMOUSEMOVE
) &&
813 IS_BTN_MESSAGE(Msg
->Msg
.message
, DOWN
) &&
814 co_IntActivateWindowMouse(ThreadQueue
, &Msg
->Msg
, MsgWindow
, &HitTest
) )
816 UserDerefObjectCo(MsgWindow
);
817 /* eat the message, search again */
822 UserDerefObjectCo(MsgWindow
);
826 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
831 // UserDereferenceObject(MsgWindow);
837 if ( ( Msg
->Msg
.hwnd
&& Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
838 Msg
->Msg
.message
<= WM_MOUSELAST
) &&
839 co_IntTranslateMouseMessage( ThreadQueue
,
843 /* FIXME - check message filter again, if the message doesn't match anymore,
846 /* eat the message, search again */
851 if ( ISITHOOKED(WH_MOUSE
) &&
852 Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
853 Msg
->Msg
.message
<= WM_MOUSELAST
)
855 MHook
.pt
= Msg
->Msg
.pt
;
856 MHook
.hwnd
= Msg
->Msg
.hwnd
;
857 MHook
.wHitTestCode
= HitTest
;
858 MHook
.dwExtraInfo
= 0;
859 if (co_HOOK_CallHooks( WH_MOUSE
,
860 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
864 if (ISITHOOKED(WH_CBT
))
866 MHook
.pt
= Msg
->Msg
.pt
;
867 MHook
.hwnd
= Msg
->Msg
.hwnd
;
868 MHook
.wHitTestCode
= HitTest
;
869 MHook
.dwExtraInfo
= 0;
870 co_HOOK_CallHooks( WH_CBT
,
879 if ( ISITHOOKED(WH_KEYBOARD
) &&
880 (Msg
->Msg
.message
== WM_KEYDOWN
|| Msg
->Msg
.message
== WM_KEYUP
) )
882 if (co_HOOK_CallHooks( WH_KEYBOARD
,
883 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
884 LOWORD(Msg
->Msg
.wParam
),
887 if (ISITHOOKED(WH_CBT
))
889 /* skip this message */
890 co_HOOK_CallHooks( WH_CBT
,
892 LOWORD(Msg
->Msg
.wParam
),
898 // The WH_GETMESSAGE hook enables an application to monitor messages about to
899 // be returned by the GetMessage or PeekMessage function.
900 if (ISITHOOKED(WH_GETMESSAGE
))
902 //DPRINT1("Peek WH_GETMESSAGE -> %x\n",&Msg);
903 co_HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, RemoveMsg
& PM_REMOVE
, (LPARAM
)&Msg
->Msg
);
912 co_IntGetPeekMessage( PMSG pMsg
,
924 co_IntWaitMessage( PWINDOW_OBJECT Window
,
929 PUSER_MESSAGE_QUEUE ThreadQueue
;
930 NTSTATUS Status
= STATUS_SUCCESS
;
933 pti
= PsGetCurrentThreadWin32Thread();
934 ThreadQueue
= pti
->MessageQueue
;
938 if ( co_IntPeekMessage( &Msg
,
946 /* Nothing found. Wait for new messages. */
947 Status
= co_MsqWaitForNewMessages( ThreadQueue
,
952 while ( (STATUS_WAIT_0
<= Status
&& Status
<= STATUS_WAIT_63
) ||
953 STATUS_TIMEOUT
== Status
);
955 SetLastNtError(Status
);
957 DPRINT1("Exit co_IntWaitMessage on error!\n");
963 static NTSTATUS FASTCALL
964 CopyMsgToKernelMem(MSG
*KernelModeMsg
, MSG
*UserModeMsg
, PMSGMEMORY MsgMemoryEntry
)
971 *KernelModeMsg
= *UserModeMsg
;
973 /* See if this message type is present in the table */
974 if (NULL
== MsgMemoryEntry
)
976 /* Not present, no copying needed */
977 return STATUS_SUCCESS
;
980 /* Determine required size */
981 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
985 /* Allocate kernel mem */
986 KernelMem
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
987 if (NULL
== KernelMem
)
989 DPRINT1("Not enough memory to copy message to kernel mem\n");
990 return STATUS_NO_MEMORY
;
992 KernelModeMsg
->lParam
= (LPARAM
) KernelMem
;
994 /* Copy data if required */
995 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_READ
))
997 Status
= MmCopyFromCaller(KernelMem
, (PVOID
) UserModeMsg
->lParam
, Size
);
998 if (! NT_SUCCESS(Status
))
1000 DPRINT1("Failed to copy message to kernel: invalid usermode buffer\n");
1001 ExFreePoolWithTag(KernelMem
, TAG_MSG
);
1007 /* Make sure we don't pass any secrets to usermode */
1008 RtlZeroMemory(KernelMem
, Size
);
1013 KernelModeMsg
->lParam
= 0;
1016 return STATUS_SUCCESS
;
1019 static NTSTATUS FASTCALL
1020 CopyMsgToUserMem(MSG
*UserModeMsg
, MSG
*KernelModeMsg
)
1023 PMSGMEMORY MsgMemoryEntry
;
1026 /* See if this message type is present in the table */
1027 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
->message
);
1028 if (NULL
== MsgMemoryEntry
)
1030 /* Not present, no copying needed */
1031 return STATUS_SUCCESS
;
1034 /* Determine required size */
1035 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
1039 /* Copy data if required */
1040 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_WRITE
))
1042 Status
= MmCopyToCaller((PVOID
) UserModeMsg
->lParam
, (PVOID
) KernelModeMsg
->lParam
, Size
);
1043 if (! NT_SUCCESS(Status
))
1045 DPRINT1("Failed to copy message from kernel: invalid usermode buffer\n");
1046 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1051 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1054 return STATUS_SUCCESS
;
1058 UserPostThreadMessage( DWORD idThread
,
1065 PTHREADINFO pThread
;
1066 LARGE_INTEGER LargeTickCount
;
1069 DPRINT1("UserPostThreadMessage wParam 0x%x lParam 0x%x\n", wParam
,lParam
);
1071 if (FindMsgMemory(Msg
) != 0)
1073 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1077 Status
= PsLookupThreadByThreadId((HANDLE
)idThread
,&peThread
);
1079 if( Status
== STATUS_SUCCESS
)
1081 pThread
= (PTHREADINFO
)peThread
->Tcb
.Win32Thread
;
1082 if( !pThread
|| !pThread
->MessageQueue
|| (pThread
->TIF_flags
& TIF_INCLEANUP
))
1084 ObDereferenceObject( peThread
);
1088 Message
.hwnd
= NULL
;
1089 Message
.message
= Msg
;
1090 Message
.wParam
= wParam
;
1091 Message
.lParam
= lParam
;
1092 Message
.pt
= gpsi
->ptCursor
;
1094 KeQueryTickCount(&LargeTickCount
);
1095 pThread
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1096 MsqPostMessage(pThread
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1097 ObDereferenceObject( peThread
);
1102 SetLastNtError( Status
);
1108 UserPostMessage( HWND Wnd
,
1115 LARGE_INTEGER LargeTickCount
;
1117 if (FindMsgMemory(Msg
) != 0)
1119 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1124 return UserPostThreadMessage( PtrToInt(PsGetCurrentThreadId()),
1129 if (Wnd
== HWND_BROADCAST
)
1132 PWINDOW_OBJECT DesktopWindow
;
1135 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1136 List
= IntWinListChildren(DesktopWindow
);
1140 for (i
= 0; List
[i
]; i
++)
1141 UserPostMessage(List
[i
], Msg
, wParam
, lParam
);
1147 PWINDOW_OBJECT Window
;
1149 Window
= UserGetWindowObject(Wnd
);
1150 if ( !Window
|| !Window
->Wnd
)
1155 pti
= Window
->Wnd
->head
.pti
;
1156 if ( pti
->TIF_flags
& TIF_INCLEANUP
)
1158 DPRINT1("Attempted to post message to window 0x%x when the thread is in cleanup!\n", Wnd
);
1162 if ( Window
->state
& WINDOWSTATUS_DESTROYING
)
1164 DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd
);
1165 /* FIXME - last error code? */
1171 MsqPostQuitMessage(Window
->MessageQueue
, wParam
);
1176 Message
.message
= Msg
;
1177 Message
.wParam
= wParam
;
1178 Message
.lParam
= lParam
;
1179 Message
.pt
= gpsi
->ptCursor
;
1180 KeQueryTickCount(&LargeTickCount
);
1181 pti
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1182 MsqPostMessage(Window
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1190 co_IntSendMessage( HWND hWnd
,
1195 ULONG_PTR Result
= 0;
1196 if(co_IntSendMessageTimeout(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
))
1198 return (LRESULT
)Result
;
1205 co_IntSendMessageTimeoutSingle( HWND hWnd
,
1211 ULONG_PTR
*uResult
)
1215 PWINDOW_OBJECT Window
= NULL
;
1216 PMSGMEMORY MsgMemoryEntry
;
1217 INT lParamBufferSize
;
1218 LPARAM lParamPacked
;
1219 PTHREADINFO Win32Thread
;
1220 DECLARE_RETURN(LRESULT
);
1221 USER_REFERENCE_ENTRY Ref
;
1223 if (!(Window
= UserGetWindowObject(hWnd
)))
1228 UserRefObjectCo(Window
, &Ref
);
1230 Win32Thread
= PsGetCurrentThreadWin32Thread();
1232 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1234 if ( NULL
!= Win32Thread
&&
1235 Window
->MessageQueue
== Win32Thread
->MessageQueue
)
1237 if (Win32Thread
->TIF_flags
& TIF_INCLEANUP
)
1239 /* Never send messages to exiting threads */
1243 /* See if this message type is present in the table */
1244 MsgMemoryEntry
= FindMsgMemory(Msg
);
1245 if (NULL
== MsgMemoryEntry
)
1247 lParamBufferSize
= -1;
1251 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1254 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
)))
1256 DPRINT1("Failed to pack message parameters\n");
1260 Result
= (ULONG_PTR
)co_IntCallWindowProc( Window
->Wnd
->lpfnWndProc
,
1261 !Window
->Wnd
->Unicode
,
1272 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1274 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
)))
1276 DPRINT1("Failed to unpack message parameters\n");
1283 if (uFlags
& SMTO_ABORTIFHUNG
&& MsqIsHung(Window
->MessageQueue
))
1285 /* FIXME - Set a LastError? */
1289 if (Window
->state
& WINDOWSTATUS_DESTROYING
)
1291 /* FIXME - last error? */
1292 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1298 Status
= co_MsqSendMessage( Window
->MessageQueue
,
1304 (uFlags
& SMTO_BLOCK
),
1308 while ((STATUS_TIMEOUT
== Status
) &&
1309 (uFlags
& SMTO_NOTIMEOUTIFNOTHUNG
) &&
1310 !MsqIsHung(Window
->MessageQueue
));
1312 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1314 if (STATUS_TIMEOUT
== Status
)
1318 Microsoft Windows 2000: If GetLastError returns zero, then the function
1320 XP+ : If the function fails or times out, the return value is zero.
1321 To get extended error information, call GetLastError. If GetLastError
1322 returns ERROR_TIMEOUT, then the function timed out.
1324 SetLastWin32Error(ERROR_TIMEOUT
);
1327 else if (! NT_SUCCESS(Status
))
1329 SetLastNtError(Status
);
1336 if (Window
) UserDerefObjectCo(Window
);
1341 co_IntSendMessageTimeout( HWND hWnd
,
1347 ULONG_PTR
*uResult
)
1349 PWINDOW_OBJECT DesktopWindow
;
1353 if (HWND_BROADCAST
!= hWnd
)
1355 return co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1358 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1359 if (NULL
== DesktopWindow
)
1361 SetLastWin32Error(ERROR_INTERNAL_ERROR
);
1365 Children
= IntWinListChildren(DesktopWindow
);
1366 if (NULL
== Children
)
1371 for (Child
= Children
; NULL
!= *Child
; Child
++)
1373 co_IntSendMessageTimeoutSingle(*Child
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1376 ExFreePool(Children
);
1378 return (LRESULT
) TRUE
;
1382 /* This function posts a message if the destination's message queue belongs to
1383 another thread, otherwise it sends the message. It does not support broadcast
1386 co_IntPostOrSendMessage( HWND hWnd
,
1393 PWINDOW_OBJECT Window
;
1395 if ( hWnd
== HWND_BROADCAST
)
1400 if(!(Window
= UserGetWindowObject(hWnd
)))
1405 pti
= PsGetCurrentThreadWin32Thread();
1407 if ( Window
->MessageQueue
!= pti
->MessageQueue
&&
1408 FindMsgMemory(Msg
) == 0 )
1410 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1414 if ( !co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
) )
1420 return (LRESULT
)Result
;
1424 co_IntDoSendMessage( HWND hWnd
,
1429 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1432 LRESULT Result
= TRUE
;
1434 PWINDOW_OBJECT Window
= NULL
;
1435 NTUSERSENDMESSAGEINFO Info
;
1438 PMSGMEMORY MsgMemoryEntry
;
1440 RtlZeroMemory(&Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1442 /* FIXME: Call hooks. */
1443 if (HWND_BROADCAST
!= hWnd
)
1445 Window
= UserGetWindowObject(hWnd
);
1446 if ( !Window
|| !Window
->Wnd
)
1448 /* Tell usermode to not touch this one */
1449 Info
.HandledByKernel
= TRUE
;
1450 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1455 /* Check for an exiting window. */
1456 if (Window
&& Window
->state
& WINDOWSTATUS_DESTROYING
)
1458 DPRINT1("co_IntDoSendMessage Window Exiting!\n");
1461 /* See if the current thread can handle the message */
1462 pti
= PsGetCurrentThreadWin32Thread();
1464 // This is checked in user mode!!!!!!!
1465 if ( HWND_BROADCAST
!= hWnd
&&
1467 Window
->MessageQueue
== pti
->MessageQueue
&&
1468 !ISITHOOKED(WH_CALLWNDPROC
) &&
1469 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
1470 ( Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
) )
1472 /* Gather the information usermode needs to call the window proc directly */
1473 Info
.HandledByKernel
= FALSE
;
1475 Status
= MmCopyFromCaller(&(Info
.Ansi
), &(UnsafeInfo
->Ansi
),
1477 if (! NT_SUCCESS(Status
))
1479 Info
.Ansi
= ! Window
->Wnd
->Unicode
;
1482 Info
.Ansi
= !Window
->Wnd
->Unicode
;
1483 Info
.Proc
= Window
->Wnd
->lpfnWndProc
;
1487 /* Must be handled by other thread */
1488 // if (HWND_BROADCAST != hWnd)
1490 // UserDereferenceObject(Window);
1492 Info
.HandledByKernel
= TRUE
;
1493 UserModeMsg
.hwnd
= hWnd
;
1494 UserModeMsg
.message
= Msg
;
1495 UserModeMsg
.wParam
= wParam
;
1496 UserModeMsg
.lParam
= lParam
;
1497 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1499 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1500 if (! NT_SUCCESS(Status
))
1502 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1503 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1504 return (dsm
? 0 : -1);
1509 Result
= co_IntSendMessage( KernelModeMsg
.hwnd
,
1510 KernelModeMsg
.message
,
1511 KernelModeMsg
.wParam
,
1512 KernelModeMsg
.lParam
);
1516 Result
= co_IntSendMessageTimeout( KernelModeMsg
.hwnd
,
1517 KernelModeMsg
.message
,
1518 KernelModeMsg
.wParam
,
1519 KernelModeMsg
.lParam
,
1525 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1526 if (! NT_SUCCESS(Status
))
1528 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1529 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1530 return(dsm
? 0 : -1);
1534 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1535 if (! NT_SUCCESS(Status
))
1537 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1540 return (LRESULT
)Result
;
1545 UserSendNotifyMessage( HWND hWnd
,
1552 if (FindMsgMemory(Msg
) != 0)
1554 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1558 // Basicly the same as IntPostOrSendMessage
1559 if (hWnd
== HWND_BROADCAST
) //Handle Broadcast
1562 PWINDOW_OBJECT DesktopWindow
;
1565 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1566 List
= IntWinListChildren(DesktopWindow
);
1570 for (i
= 0; List
[i
]; i
++)
1572 UserSendNotifyMessage(List
[i
], Msg
, wParam
, lParam
);
1581 PWINDOW_OBJECT Window
;
1584 if ( !(Window
= UserGetWindowObject(hWnd
)) ) return FALSE
;
1586 pti
= PsGetCurrentThreadWin32Thread();
1588 if (Window
->MessageQueue
!= pti
->MessageQueue
)
1589 { // Send message w/o waiting for it.
1590 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1593 { // Handle message and callback.
1594 Message
.hwnd
= hWnd
;
1595 Message
.message
= Msg
;
1596 Message
.wParam
= wParam
;
1597 Message
.lParam
= lParam
;
1599 Result
= co_IntSendMessageTimeoutSingle( hWnd
,
1613 IntGetQueueStatus(BOOL ClearChanges
)
1616 PUSER_MESSAGE_QUEUE Queue
;
1618 DECLARE_RETURN(DWORD
);
1620 DPRINT("Enter IntGetQueueStatus\n");
1622 pti
= PsGetCurrentThreadWin32Thread();
1623 Queue
= pti
->MessageQueue
;
1625 Result
= MAKELONG(Queue
->QueueBits
, Queue
->ChangedBits
);
1628 Queue
->ChangedBits
= 0;
1634 DPRINT("Leave IntGetQueueStatus, ret=%i\n",_ret_
);
1639 IntInitMessagePumpHook()
1641 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1643 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
++;
1650 IntUninitMessagePumpHook()
1652 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1654 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
<= 0)
1658 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
--;
1664 /** Functions ******************************************************************/
1667 NtUserPostMessage(HWND hWnd
,
1672 DECLARE_RETURN(BOOL
);
1674 DPRINT("Enter NtUserPostMessage\n");
1675 UserEnterExclusive();
1677 RETURN( UserPostMessage(hWnd
, Msg
, wParam
, lParam
));
1680 DPRINT("Leave NtUserPostMessage, ret=%i\n",_ret_
);
1686 NtUserPostThreadMessage(DWORD idThread
,
1691 DECLARE_RETURN(BOOL
);
1693 DPRINT("Enter NtUserPostThreadMessage\n");
1694 UserEnterExclusive();
1696 RETURN( UserPostThreadMessage( idThread
,
1702 DPRINT("Leave NtUserPostThreadMessage, ret=%i\n",_ret_
);
1708 NtUserQuerySendMessage(DWORD Unknown0
)
1716 ////////// API on the way out!
1718 NtUserSendMessageTimeout( HWND hWnd
,
1725 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1729 DECLARE_RETURN(BOOL
);
1731 DPRINT("Enter NtUserSendMessageTimeout\n");
1732 UserEnterExclusive();
1734 dsm
.uFlags
= uFlags
;
1735 dsm
.uTimeout
= uTimeout
;
1736 Result
= co_IntDoSendMessage(hWnd
, Msg
, wParam
, lParam
, &dsm
, UnsafeInfo
);
1737 if(uResult
!= NULL
&& Result
!= 0)
1741 Status
= MmCopyToCaller(uResult
, &dsm
.Result
, sizeof(ULONG_PTR
));
1742 if(!NT_SUCCESS(Status
))
1744 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1751 DPRINT("Leave NtUserSendMessageTimeout, ret=%i\n",_ret_
);
1757 NtUserSendMessage( HWND Wnd
,
1761 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1763 DECLARE_RETURN(BOOL
);
1765 DPRINT("Enter NtUserSendMessage\n");
1766 UserEnterExclusive();
1768 RETURN(co_IntDoSendMessage(Wnd
, Msg
, wParam
, lParam
, NULL
, UnsafeInfo
));
1771 DPRINT("Leave NtUserSendMessage, ret=%i\n",_ret_
);
1778 NtUserWaitMessage(VOID
)
1780 DECLARE_RETURN(BOOL
);
1782 DPRINT("EnterNtUserWaitMessage\n");
1783 UserEnterExclusive();
1785 RETURN(co_IntWaitMessage(NULL
, 0, 0));
1788 DPRINT("Leave NtUserWaitMessage, ret=%i\n",_ret_
);
1795 NtUserGetMessage( PNTUSERGETMESSAGEINFO UnsafeInfo
,
1800 * FUNCTION: Get a message from the calling thread's message queue.
1802 * UnsafeMsg - Pointer to the structure which receives the returned message.
1803 * Wnd - Window whose messages are to be retrieved.
1804 * MsgFilterMin - Integer value of the lowest message value to be
1806 * MsgFilterMax - Integer value of the highest message value to be
1811 NTUSERGETMESSAGEINFO Info
;
1813 /* FIXME: if initialization is removed, gcc complains that this may be used before initialization. Please review */
1814 PWINDOW_OBJECT Window
= NULL
;
1815 PMSGMEMORY MsgMemoryEntry
;
1819 DECLARE_RETURN(BOOL
);
1820 // USER_REFERENCE_ENTRY Ref;
1822 DPRINT("Enter NtUserGetMessage\n");
1823 UserEnterExclusive();
1825 /* Validate input */
1826 if (hWnd
&& !(Window
= UserGetWindowObject(hWnd
)))
1831 // if (Window) UserRefObjectCo(Window, &Ref);
1833 if (MsgFilterMax
< MsgFilterMin
)
1841 GotMessage
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
);
1845 /* See if this message type is present in the table */
1846 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
1847 if (NULL
== MsgMemoryEntry
)
1849 /* Not present, no copying needed */
1850 Info
.LParamSize
= 0;
1854 /* Determine required size */
1855 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
1857 /* Allocate required amount of user-mode memory */
1858 Info
.LParamSize
= Size
;
1860 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
1861 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
1863 if (! NT_SUCCESS(Status
))
1865 SetLastNtError(Status
);
1868 /* Transfer lParam data to user-mode mem */
1869 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
1870 if (! NT_SUCCESS(Status
))
1872 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
1873 &Info
.LParamSize
, MEM_DECOMMIT
);
1874 SetLastNtError(Status
);
1877 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
1879 if (Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
1881 ExFreePool((void *) Msg
.Msg
.lParam
);
1883 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
1884 if (! NT_SUCCESS(Status
))
1886 SetLastNtError(Status
);
1890 else if (! co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
))
1895 while (! GotMessage
);
1897 RETURN( WM_QUIT
!= Info
.Msg
.message
);
1900 // if (Window) UserDerefObjectCo(Window);
1902 DPRINT("Leave NtUserGetMessage\n");
1918 DECLARE_RETURN(BOOL
);
1920 DPRINT("Enter NtUserGetMessage\n");
1921 UserEnterExclusive();
1923 if ( (MsgFilterMin
|MsgFilterMax
) & ~WM_MAXIMUM
)
1925 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1929 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
, TRUE
);
1935 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
1936 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
1938 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1940 SetLastNtError(_SEH2_GetExceptionCode());
1948 DPRINT("Leave NtUserGetMessage\n");
1954 NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
1962 NTUSERGETMESSAGEINFO Info
;
1963 PWINDOW_OBJECT Window
;
1964 PMSGMEMORY MsgMemoryEntry
;
1968 DECLARE_RETURN(BOOL
);
1970 DPRINT("Enter NtUserPeekMessage\n");
1971 UserEnterExclusive();
1973 if (hWnd
== (HWND
)-1 || hWnd
== (HWND
)0x0000FFFF || hWnd
== (HWND
)0xFFFFFFFF)
1976 /* Validate input */
1977 if (hWnd
&& hWnd
!= (HWND
)1)
1979 if (!(Window
= UserGetWindowObject(hWnd
)))
1986 Window
= (PWINDOW_OBJECT
)hWnd
;
1989 if (MsgFilterMax
< MsgFilterMin
)
1995 Present
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
);
2000 /* See if this message type is present in the table */
2001 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
2002 if (NULL
== MsgMemoryEntry
)
2004 /* Not present, no copying needed */
2005 Info
.LParamSize
= 0;
2009 /* Determine required size */
2010 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
2012 /* Allocate required amount of user-mode memory */
2013 Info
.LParamSize
= Size
;
2015 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
2016 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
2017 if (! NT_SUCCESS(Status
))
2019 SetLastNtError(Status
);
2022 /* Transfer lParam data to user-mode mem */
2023 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
2024 if (! NT_SUCCESS(Status
))
2026 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
2027 &Info
.LParamSize
, MEM_RELEASE
);
2028 SetLastNtError(Status
);
2031 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
2033 if (RemoveMsg
&& Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
2035 ExFreePool((void *) Msg
.Msg
.lParam
);
2037 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
2038 if (! NT_SUCCESS(Status
))
2040 SetLastNtError(Status
);
2048 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2064 DECLARE_RETURN(BOOL
);
2066 DPRINT("Enter NtUserPeekMessage\n");
2067 UserEnterExclusive();
2069 if ( RemoveMsg
& PM_BADMSGFLAGS
)
2071 SetLastWin32Error(ERROR_INVALID_FLAGS
);
2075 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
, FALSE
);
2081 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
2082 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
2084 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2086 SetLastNtError(_SEH2_GetExceptionCode());
2094 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2101 NtUserCallMsgFilter(
2105 BOOL BadChk
= FALSE
, Ret
= FALSE
;
2107 DECLARE_RETURN(BOOL
);
2109 DPRINT("Enter NtUserCallMsgFilter\n");
2110 UserEnterExclusive();
2115 ProbeForRead((PVOID
)lpmsg
,
2118 RtlCopyMemory( &Msg
,
2122 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2131 if (BadChk
) RETURN( FALSE
);
2133 if ( ISITHOOKED(WH_SYSMSGFILTER
) &&
2134 co_HOOK_CallHooks( WH_SYSMSGFILTER
, code
, 0, (LPARAM
)&Msg
))
2140 if ( ISITHOOKED(WH_MSGFILTER
) )
2142 Ret
= co_HOOK_CallHooks( WH_MSGFILTER
, code
, 0, (LPARAM
)&Msg
);
2148 ProbeForWrite((PVOID
)lpmsg
,
2151 RtlCopyMemory((PVOID
)lpmsg
,
2155 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2160 if (BadChk
) RETURN( FALSE
);
2164 DPRINT("Leave NtUserCallMsgFilter. ret=%i\n", _ret_
);
2170 NtUserDispatchMessage(PMSG UnsafeMsgInfo
)
2176 UserEnterExclusive();
2179 ProbeForRead(UnsafeMsgInfo
, sizeof(MSG
), 1);
2180 RtlCopyMemory(&SafeMsg
, UnsafeMsgInfo
, sizeof(MSG
));
2182 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2184 SetLastNtError(_SEH2_GetExceptionCode());
2189 if (!Hit
) Res
= IntDispatchMessage(&SafeMsg
);
2197 NtUserTranslateMessage(LPMSG lpMsg
,
2202 DECLARE_RETURN(BOOL
);
2204 DPRINT("Enter NtUserTranslateMessage\n");
2205 UserEnterExclusive();
2207 Status
= MmCopyFromCaller(&SafeMsg
, lpMsg
, sizeof(MSG
));
2208 if(!NT_SUCCESS(Status
))
2210 SetLastNtError(Status
);
2214 RETURN( IntTranslateKbdMessage(&SafeMsg
, dwhkl
));
2217 DPRINT("Leave NtUserTranslateMessage: ret=%i\n",_ret_
);
2228 ULONG_PTR ResultInfo
,
2229 DWORD dwType
, // fnID?
2232 LRESULT lResult
= 0;
2234 BOOL BadChk
= FALSE
;
2235 PWINDOW_OBJECT Window
= NULL
;
2236 USER_REFERENCE_ENTRY Ref
;
2238 UserEnterExclusive();
2240 /* Validate input */
2241 if (hWnd
&& (hWnd
!= INVALID_HANDLE_VALUE
) && !(Window
= UserGetWindowObject(hWnd
)))
2248 case FNID_DEFWINDOWPROC
:
2249 UserRefObjectCo(Window
, &Ref
);
2250 lResult
= IntDefWindowProc(Window
, Msg
, wParam
, lParam
, Ansi
);
2252 UserDerefObjectCo(Window
);
2254 case FNID_SENDNOTIFYMESSAGE
:
2255 Ret
= UserSendNotifyMessage(hWnd
, Msg
, wParam
, lParam
);
2257 case FNID_BROADCASTSYSTEMMESSAGE
:
2260 DWORD_PTR RetVal
= 0;
2266 ProbeForWrite((PVOID
)ResultInfo
,
2267 sizeof(BROADCASTPARM
),
2269 RtlCopyMemory(&parm
, (PVOID
)ResultInfo
, sizeof(BROADCASTPARM
));
2271 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2281 if ( parm
.recipients
& BSM_ALLDESKTOPS
||
2282 parm
.recipients
== BSM_ALLCOMPONENTS
)
2285 else if (parm
.recipients
& BSM_APPLICATIONS
)
2287 if (parm
.flags
& BSF_QUERY
)
2289 if (parm
.flags
& BSF_FORCEIFHUNG
|| parm
.flags
& BSF_NOHANG
)
2291 co_IntSendMessageTimeout( HWND_BROADCAST
,
2299 else if (parm
.flags
& BSF_NOTIMEOUTIFNOTHUNG
)
2301 co_IntSendMessageTimeout( HWND_BROADCAST
,
2305 SMTO_NOTIMEOUTIFNOTHUNG
,
2311 co_IntSendMessageTimeout( HWND_BROADCAST
,
2320 else if (parm
.flags
& BSF_POSTMESSAGE
)
2322 Ret
= UserPostMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2324 else if ( parm
.flags
& BSF_SENDNOTIFYMESSAGE
)
2326 Ret
= UserSendNotifyMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2331 case FNID_SENDMESSAGECALLBACK
:
2333 // CallNextHook bypass.
2334 case FNID_CALLWNDPROC
:
2335 case FNID_CALLWNDPROCRET
:
2337 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
2338 PHOOK NextObj
, Hook
= ClientInfo
->phkCurrent
;
2340 if (!ClientInfo
|| !Hook
) break;
2342 UserReferenceObject(Hook
);
2344 if (Hook
->Thread
&& (Hook
->Thread
!= PsGetCurrentThread()))
2346 UserDereferenceObject(Hook
);
2350 NextObj
= IntGetNextHook(Hook
);
2351 ClientInfo
->phkCurrent
= NextObj
;
2353 if ( Hook
->HookId
== WH_CALLWNDPROC
)
2358 CWP
.wParam
= wParam
;
2359 CWP
.lParam
= lParam
;
2360 DPRINT("WH_CALLWNDPROC: Hook %x NextHook %x\n", Hook
, NextObj
);
2362 lResult
= co_IntCallHookProc( Hook
->HookId
,
2364 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2375 CWPR
.wParam
= wParam
;
2376 CWPR
.lParam
= lParam
;
2377 CWPR
.lResult
= ClientInfo
->dwHookData
;
2379 lResult
= co_IntCallHookProc( Hook
->HookId
,
2381 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2387 UserDereferenceObject(Hook
);
2388 lResult
= (LRESULT
) NextObj
;
2395 case FNID_DEFWINDOWPROC
:
2396 case FNID_CALLWNDPROC
:
2397 case FNID_CALLWNDPROCRET
:
2402 ProbeForWrite((PVOID
)ResultInfo
, sizeof(LRESULT
), 1);
2403 RtlCopyMemory((PVOID
)ResultInfo
, &lResult
, sizeof(LRESULT
));
2405 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2418 return BadChk
? FALSE
: Ret
;
2421 #define INFINITE 0xFFFFFFFF
2422 #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
2426 NtUserWaitForInputIdle(
2428 IN DWORD dwMilliseconds
,
2432 PPROCESSINFO W32Process
;
2435 LARGE_INTEGER Timeout
;
2436 ULONGLONG StartTime
, Run
, Elapsed
= 0;
2438 UserEnterExclusive();
2440 Status
= ObReferenceObjectByHandle(hProcess
,
2441 PROCESS_QUERY_INFORMATION
,
2447 if (!NT_SUCCESS(Status
))
2450 SetLastNtError(Status
);
2454 W32Process
= (PPROCESSINFO
)Process
->Win32Process
;
2457 ObDereferenceObject(Process
);
2459 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2463 EngCreateEvent((PEVENT
*)&W32Process
->InputIdleEvent
);
2465 Handles
[0] = Process
;
2466 Handles
[1] = W32Process
->InputIdleEvent
;
2470 ObDereferenceObject(Process
);
2472 return STATUS_SUCCESS
; /* no event to wait on */
2475 StartTime
= EngGetTickCount();
2477 Run
= dwMilliseconds
;
2479 DPRINT("WFII: waiting for %p\n", Handles
[1] );
2482 Timeout
.QuadPart
= Run
- Elapsed
;
2484 Status
= KeWaitForMultipleObjects( 2,
2490 dwMilliseconds
== INFINITE
? NULL
: &Timeout
,
2492 UserEnterExclusive();
2494 if (!NT_SUCCESS(Status
))
2496 SetLastNtError(Status
);
2497 Status
= WAIT_FAILED
;
2504 Status
= WAIT_FAILED
;
2510 co_IntPeekMessage( &Msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2514 case STATUS_USER_APC
:
2515 case STATUS_ALERTED
:
2516 case STATUS_TIMEOUT
:
2517 DPRINT1("WFII: timeout\n");
2518 Status
= STATUS_TIMEOUT
;
2522 DPRINT1("WFII: finished\n");
2523 Status
= STATUS_SUCCESS
;
2527 if (dwMilliseconds
!= INFINITE
)
2529 Elapsed
= EngGetTickCount() - StartTime
;
2532 Status
= STATUS_TIMEOUT
;
2539 if (W32Process
->InputIdleEvent
)
2541 EngDeleteEvent((PEVENT
)W32Process
->InputIdleEvent
);
2542 W32Process
->InputIdleEvent
= NULL
;
2544 ObDereferenceObject(Process
);