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
;
458 if(!IntGetWindowStationObject(InputWindowStation
))
462 CurInfo
= IntGetSysCursorInfo(InputWindowStation
);
463 wParam
= (WPARAM
)(CurInfo
->ButtonsDown
);
464 ObDereferenceObject(InputWindowStation
);
466 co_IntSendMessage(Msg
->hwnd
, WM_MOUSEMOVE
, wParam
, Msg
->lParam
);
467 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
470 case WM_NCLBUTTONDOWN
:
471 case WM_NCMBUTTONDOWN
:
472 case WM_NCRBUTTONDOWN
:
473 case WM_NCXBUTTONDOWN
:
474 case WM_NCLBUTTONDBLCLK
:
475 case WM_NCMBUTTONDBLCLK
:
476 case WM_NCRBUTTONDBLCLK
:
477 case WM_NCXBUTTONDBLCLK
:
479 co_IntSendMessage(Msg
->hwnd
, WM_NCMOUSEMOVE
, (WPARAM
)Msg
->wParam
, Msg
->lParam
);
480 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
487 co_IntActivateWindowMouse(
488 PUSER_MESSAGE_QUEUE ThreadQueue
,
490 PWINDOW_OBJECT MsgWindow
,
494 PWINDOW_OBJECT Parent
;
496 ASSERT_REFS_CO(MsgWindow
);
498 if(*HitTest
== (USHORT
)HTTRANSPARENT
)
500 /* eat the message, search again! */
504 Parent
= IntGetParent(MsgWindow
);//fixme: deref retval?
506 /* If no parent window, pass MsgWindows HWND as wParam. Fixes bug #3111 */
507 Result
= co_IntSendMessage(MsgWindow
->hSelf
,
509 (WPARAM
) (Parent
? Parent
->hSelf
: MsgWindow
->hSelf
),
510 (LPARAM
)MAKELONG(*HitTest
, Msg
->message
)
515 case MA_NOACTIVATEANDEAT
:
519 case MA_ACTIVATEANDEAT
:
520 co_IntMouseActivateWindow(MsgWindow
);
524 co_IntMouseActivateWindow(MsgWindow
);
532 co_IntTranslateMouseMessage(
533 PUSER_MESSAGE_QUEUE ThreadQueue
,
538 PWINDOW_OBJECT Window
;
539 USER_REFERENCE_ENTRY Ref
, DesktopRef
;
541 if(!(Window
= UserGetWindowObject(Msg
->hwnd
)))
543 /* let's just eat the message?! */
547 UserRefObjectCo(Window
, &Ref
);
549 if ( ThreadQueue
== Window
->MessageQueue
&&
550 ThreadQueue
->CaptureWindow
!= Window
->hSelf
)
552 /* only send WM_NCHITTEST messages if we're not capturing the window! */
553 *HitTest
= co_IntSendMessage(Window
->hSelf
, WM_NCHITTEST
, 0,
554 MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
));
556 if (*HitTest
== (USHORT
)HTTRANSPARENT
)
558 PWINDOW_OBJECT DesktopWindow
;
559 HWND hDesktop
= IntGetDesktopWindow();
561 if ((DesktopWindow
= UserGetWindowObject(hDesktop
)))
565 UserRefObjectCo(DesktopWindow
, &DesktopRef
);
567 co_WinPosWindowFromPoint(DesktopWindow
, Window
->MessageQueue
, &Msg
->pt
, &Wnd
);
572 /* post the message to the other window */
573 Msg
->hwnd
= Wnd
->hSelf
;
574 if(!(Wnd
->Status
& WINDOWSTATUS_DESTROYING
))
576 MsqPostMessage(Wnd
->MessageQueue
, Msg
, FALSE
,
577 Msg
->message
== WM_MOUSEMOVE
? QS_MOUSEMOVE
:
581 /* eat the message */
582 UserDereferenceObject(Wnd
);
583 UserDerefObjectCo(DesktopWindow
);
584 UserDerefObjectCo(Window
);
587 UserDereferenceObject(Wnd
);
590 UserDerefObjectCo(DesktopWindow
);
599 if ( gspv
.bMouseClickLock
&&
600 ( (Msg
->message
== WM_LBUTTONUP
) ||
601 (Msg
->message
== WM_LBUTTONDOWN
) ) )
603 if (MsqIsClkLck(Msg
, Remove
))
605 // FIXME: drop the message, hack: use WM_NULL
606 Msg
->message
= WM_NULL
;
610 if (IS_BTN_MESSAGE(Msg
->message
, DOWN
))
612 /* generate double click messages, if necessary */
613 if ((((*HitTest
) != HTCLIENT
) ||
614 (Window
->Wnd
->pcls
->style
& CS_DBLCLKS
)) &&
615 MsqIsDblClk(Msg
, Remove
))
617 Msg
->message
+= WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
;
621 if(Msg
->message
!= WM_MOUSEWHEEL
)
624 if ((*HitTest
) != HTCLIENT
)
626 Msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
627 if ( (Msg
->message
== WM_NCRBUTTONUP
) &&
628 (((*HitTest
) == HTCAPTION
) || ((*HitTest
) == HTSYSMENU
)) )
630 Msg
->message
= WM_CONTEXTMENU
;
631 Msg
->wParam
= (WPARAM
)Window
->hSelf
;
635 Msg
->wParam
= *HitTest
;
637 Msg
->lParam
= MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
);
639 else if ( ThreadQueue
->MoveSize
== NULL
&&
640 ThreadQueue
->MenuOwner
== NULL
)
642 /* NOTE: Msg->pt should remain in screen coordinates. -- FiN */
643 Msg
->lParam
= MAKELONG(
644 Msg
->pt
.x
- (WORD
)Window
->Wnd
->rcClient
.left
,
645 Msg
->pt
.y
- (WORD
)Window
->Wnd
->rcClient
.top
);
649 UserDerefObjectCo(Window
);
654 * Internal version of PeekMessage() doing all the work
657 co_IntPeekMessage( PUSER_MESSAGE Msg
,
658 PWINDOW_OBJECT Window
,
664 LARGE_INTEGER LargeTickCount
;
665 PUSER_MESSAGE_QUEUE ThreadQueue
;
666 PUSER_MESSAGE Message
;
667 BOOL Present
, RemoveMessages
;
668 USER_REFERENCE_ENTRY Ref
;
670 MOUSEHOOKSTRUCT MHook
;
672 /* The queues and order in which they are checked are documented in the MSDN
673 article on GetMessage() */
675 pti
= PsGetCurrentThreadWin32Thread();
676 ThreadQueue
= pti
->MessageQueue
;
678 /* Inspect RemoveMsg flags */
679 /* FIXME: The only flag we process is PM_REMOVE - processing of others must still be implemented */
680 RemoveMessages
= RemoveMsg
& PM_REMOVE
;
686 KeQueryTickCount(&LargeTickCount
);
687 ThreadQueue
->LastMsgRead
= LargeTickCount
.u
.LowPart
;
689 /* Dispatch sent messages here. */
690 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
693 /* Now look for a quit message. */
695 if (ThreadQueue
->QuitPosted
)
697 /* According to the PSDK, WM_QUIT messages are always returned, regardless
698 of the filter specified */
699 Msg
->Msg
.hwnd
= NULL
;
700 Msg
->Msg
.message
= WM_QUIT
;
701 Msg
->Msg
.wParam
= ThreadQueue
->QuitExitCode
;
703 Msg
->FreeLParam
= FALSE
;
706 ThreadQueue
->QuitPosted
= FALSE
;
711 /* Now check for normal messages. */
712 Present
= co_MsqFindMessage( ThreadQueue
,
721 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
724 MsqDestroyMessage(Message
);
729 /* Check for hardware events. */
730 Present
= co_MsqFindMessage( ThreadQueue
,
739 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
742 MsqDestroyMessage(Message
);
747 /* Check for sent messages again. */
748 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
751 /* Check for paint messages. */
752 if ( IntGetPaintMessage( Window
,
759 Msg
->FreeLParam
= FALSE
;
763 if (ThreadQueue
->WakeMask
& QS_TIMER
)
764 if (PostTimerMessages(Window
)) // If there are timers ready,
765 goto CheckMessages
; // go back and process them.
767 // LOL! Polling Timer Queue? How much time is spent doing this?
768 /* Check for WM_(SYS)TIMER messages */
769 Present
= MsqGetTimerMessage( ThreadQueue
,
777 Msg
->FreeLParam
= FALSE
;
787 PWINDOW_OBJECT MsgWindow
= NULL
;
789 /* Mouse message process */
792 ( MsgWindow
= UserGetWindowObject(Msg
->Msg
.hwnd
) ) &&
793 Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
794 Msg
->Msg
.message
<= WM_MOUSELAST
)
798 UserRefObjectCo(MsgWindow
, &Ref
);
800 if ( co_IntTranslateMouseMessage( ThreadQueue
,
804 /* FIXME - check message filter again, if the message doesn't match anymore,
807 UserDerefObjectCo(MsgWindow
);
808 /* eat the message, search again */
812 if(ThreadQueue
->CaptureWindow
== NULL
)
814 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
816 if ( ( Msg
->Msg
.message
!= WM_MOUSEMOVE
&&
817 Msg
->Msg
.message
!= WM_NCMOUSEMOVE
) &&
818 IS_BTN_MESSAGE(Msg
->Msg
.message
, DOWN
) &&
819 co_IntActivateWindowMouse(ThreadQueue
, &Msg
->Msg
, MsgWindow
, &HitTest
) )
821 UserDerefObjectCo(MsgWindow
);
822 /* eat the message, search again */
827 UserDerefObjectCo(MsgWindow
);
831 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
836 // UserDereferenceObject(MsgWindow);
842 if ( ( Msg
->Msg
.hwnd
&& Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
843 Msg
->Msg
.message
<= WM_MOUSELAST
) &&
844 co_IntTranslateMouseMessage( ThreadQueue
,
848 /* FIXME - check message filter again, if the message doesn't match anymore,
851 /* eat the message, search again */
856 if ( ISITHOOKED(WH_MOUSE
) &&
857 Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
858 Msg
->Msg
.message
<= WM_MOUSELAST
)
860 MHook
.pt
= Msg
->Msg
.pt
;
861 MHook
.hwnd
= Msg
->Msg
.hwnd
;
862 MHook
.wHitTestCode
= HitTest
;
863 MHook
.dwExtraInfo
= 0;
864 if (co_HOOK_CallHooks( WH_MOUSE
,
865 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
869 if (ISITHOOKED(WH_CBT
))
871 MHook
.pt
= Msg
->Msg
.pt
;
872 MHook
.hwnd
= Msg
->Msg
.hwnd
;
873 MHook
.wHitTestCode
= HitTest
;
874 MHook
.dwExtraInfo
= 0;
875 co_HOOK_CallHooks( WH_CBT
,
884 if ( ISITHOOKED(WH_KEYBOARD
) &&
885 (Msg
->Msg
.message
== WM_KEYDOWN
|| Msg
->Msg
.message
== WM_KEYUP
) )
887 if (co_HOOK_CallHooks( WH_KEYBOARD
,
888 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
889 LOWORD(Msg
->Msg
.wParam
),
892 if (ISITHOOKED(WH_CBT
))
894 /* skip this message */
895 co_HOOK_CallHooks( WH_CBT
,
897 LOWORD(Msg
->Msg
.wParam
),
903 // The WH_GETMESSAGE hook enables an application to monitor messages about to
904 // be returned by the GetMessage or PeekMessage function.
905 if (ISITHOOKED(WH_GETMESSAGE
))
907 //DPRINT1("Peek WH_GETMESSAGE -> %x\n",&Msg);
908 co_HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, RemoveMsg
& PM_REMOVE
, (LPARAM
)&Msg
->Msg
);
917 co_IntGetPeekMessage( PMSG pMsg
,
929 co_IntWaitMessage( PWINDOW_OBJECT Window
,
934 PUSER_MESSAGE_QUEUE ThreadQueue
;
935 NTSTATUS Status
= STATUS_SUCCESS
;
938 pti
= PsGetCurrentThreadWin32Thread();
939 ThreadQueue
= pti
->MessageQueue
;
943 if ( co_IntPeekMessage( &Msg
,
951 /* Nothing found. Wait for new messages. */
952 Status
= co_MsqWaitForNewMessages( ThreadQueue
,
957 while ( (STATUS_WAIT_0
<= Status
&& Status
<= STATUS_WAIT_63
) ||
958 STATUS_TIMEOUT
== Status
);
960 SetLastNtError(Status
);
962 DPRINT1("Exit co_IntWaitMessage on error!\n");
968 static NTSTATUS FASTCALL
969 CopyMsgToKernelMem(MSG
*KernelModeMsg
, MSG
*UserModeMsg
, PMSGMEMORY MsgMemoryEntry
)
976 *KernelModeMsg
= *UserModeMsg
;
978 /* See if this message type is present in the table */
979 if (NULL
== MsgMemoryEntry
)
981 /* Not present, no copying needed */
982 return STATUS_SUCCESS
;
985 /* Determine required size */
986 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
990 /* Allocate kernel mem */
991 KernelMem
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
992 if (NULL
== KernelMem
)
994 DPRINT1("Not enough memory to copy message to kernel mem\n");
995 return STATUS_NO_MEMORY
;
997 KernelModeMsg
->lParam
= (LPARAM
) KernelMem
;
999 /* Copy data if required */
1000 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_READ
))
1002 Status
= MmCopyFromCaller(KernelMem
, (PVOID
) UserModeMsg
->lParam
, Size
);
1003 if (! NT_SUCCESS(Status
))
1005 DPRINT1("Failed to copy message to kernel: invalid usermode buffer\n");
1006 ExFreePoolWithTag(KernelMem
, TAG_MSG
);
1012 /* Make sure we don't pass any secrets to usermode */
1013 RtlZeroMemory(KernelMem
, Size
);
1018 KernelModeMsg
->lParam
= 0;
1021 return STATUS_SUCCESS
;
1024 static NTSTATUS FASTCALL
1025 CopyMsgToUserMem(MSG
*UserModeMsg
, MSG
*KernelModeMsg
)
1028 PMSGMEMORY MsgMemoryEntry
;
1031 /* See if this message type is present in the table */
1032 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
->message
);
1033 if (NULL
== MsgMemoryEntry
)
1035 /* Not present, no copying needed */
1036 return STATUS_SUCCESS
;
1039 /* Determine required size */
1040 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
1044 /* Copy data if required */
1045 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_WRITE
))
1047 Status
= MmCopyToCaller((PVOID
) UserModeMsg
->lParam
, (PVOID
) KernelModeMsg
->lParam
, Size
);
1048 if (! NT_SUCCESS(Status
))
1050 DPRINT1("Failed to copy message from kernel: invalid usermode buffer\n");
1051 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1056 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1059 return STATUS_SUCCESS
;
1063 UserPostThreadMessage( DWORD idThread
,
1070 PTHREADINFO pThread
;
1071 LARGE_INTEGER LargeTickCount
;
1074 DPRINT1("UserPostThreadMessage wParam 0x%x lParam 0x%x\n", wParam
,lParam
);
1076 if (FindMsgMemory(Msg
) != 0)
1078 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1082 Status
= PsLookupThreadByThreadId((HANDLE
)idThread
,&peThread
);
1084 if( Status
== STATUS_SUCCESS
)
1086 pThread
= (PTHREADINFO
)peThread
->Tcb
.Win32Thread
;
1087 if( !pThread
|| !pThread
->MessageQueue
|| (pThread
->TIF_flags
& TIF_INCLEANUP
))
1089 ObDereferenceObject( peThread
);
1093 Message
.hwnd
= NULL
;
1094 Message
.message
= Msg
;
1095 Message
.wParam
= wParam
;
1096 Message
.lParam
= lParam
;
1097 IntGetCursorLocation(pThread
->Desktop
->WindowStation
, &Message
.pt
);
1098 KeQueryTickCount(&LargeTickCount
);
1099 pThread
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1100 MsqPostMessage(pThread
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1101 ObDereferenceObject( peThread
);
1106 SetLastNtError( Status
);
1112 UserPostMessage( HWND Wnd
,
1119 LARGE_INTEGER LargeTickCount
;
1121 if (FindMsgMemory(Msg
) != 0)
1123 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1128 return UserPostThreadMessage( PtrToInt(PsGetCurrentThreadId()),
1133 if (Wnd
== HWND_BROADCAST
)
1136 PWINDOW_OBJECT DesktopWindow
;
1139 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1140 List
= IntWinListChildren(DesktopWindow
);
1144 for (i
= 0; List
[i
]; i
++)
1145 UserPostMessage(List
[i
], Msg
, wParam
, lParam
);
1151 PWINDOW_OBJECT Window
;
1153 Window
= UserGetWindowObject(Wnd
);
1154 if ( !Window
|| !Window
->Wnd
)
1159 pti
= Window
->Wnd
->head
.pti
;
1160 if ( pti
->TIF_flags
& TIF_INCLEANUP
)
1162 DPRINT1("Attempted to post message to window 0x%x when the thread is in cleanup!\n", Wnd
);
1166 if ( Window
->Status
& WINDOWSTATUS_DESTROYING
)
1168 DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd
);
1169 /* FIXME - last error code? */
1175 MsqPostQuitMessage(Window
->MessageQueue
, wParam
);
1180 Message
.message
= Msg
;
1181 Message
.wParam
= wParam
;
1182 Message
.lParam
= lParam
;
1183 IntGetCursorLocation(pti
->Desktop
->WindowStation
, &Message
.pt
);
1184 KeQueryTickCount(&LargeTickCount
);
1185 pti
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1186 MsqPostMessage(Window
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1194 co_IntSendMessage( HWND hWnd
,
1199 ULONG_PTR Result
= 0;
1200 if(co_IntSendMessageTimeout(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
))
1202 return (LRESULT
)Result
;
1209 co_IntSendMessageTimeoutSingle( HWND hWnd
,
1215 ULONG_PTR
*uResult
)
1219 PWINDOW_OBJECT Window
= NULL
;
1220 PMSGMEMORY MsgMemoryEntry
;
1221 INT lParamBufferSize
;
1222 LPARAM lParamPacked
;
1223 PTHREADINFO Win32Thread
;
1224 DECLARE_RETURN(LRESULT
);
1225 USER_REFERENCE_ENTRY Ref
;
1227 if (!(Window
= UserGetWindowObject(hWnd
)))
1232 UserRefObjectCo(Window
, &Ref
);
1234 Win32Thread
= PsGetCurrentThreadWin32Thread();
1236 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1238 if ( NULL
!= Win32Thread
&&
1239 Window
->MessageQueue
== Win32Thread
->MessageQueue
)
1241 if (Win32Thread
->TIF_flags
& TIF_INCLEANUP
)
1243 /* Never send messages to exiting threads */
1247 /* See if this message type is present in the table */
1248 MsgMemoryEntry
= FindMsgMemory(Msg
);
1249 if (NULL
== MsgMemoryEntry
)
1251 lParamBufferSize
= -1;
1255 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1258 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
)))
1260 DPRINT1("Failed to pack message parameters\n");
1264 Result
= (ULONG_PTR
)co_IntCallWindowProc( Window
->Wnd
->lpfnWndProc
,
1265 !Window
->Wnd
->Unicode
,
1276 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1278 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
)))
1280 DPRINT1("Failed to unpack message parameters\n");
1287 if (uFlags
& SMTO_ABORTIFHUNG
&& MsqIsHung(Window
->MessageQueue
))
1289 /* FIXME - Set a LastError? */
1293 if (Window
->Status
& WINDOWSTATUS_DESTROYING
)
1295 /* FIXME - last error? */
1296 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1302 Status
= co_MsqSendMessage( Window
->MessageQueue
,
1308 (uFlags
& SMTO_BLOCK
),
1312 while ((STATUS_TIMEOUT
== Status
) &&
1313 (uFlags
& SMTO_NOTIMEOUTIFNOTHUNG
) &&
1314 !MsqIsHung(Window
->MessageQueue
));
1316 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1318 if (STATUS_TIMEOUT
== Status
)
1322 Microsoft Windows 2000: If GetLastError returns zero, then the function
1324 XP+ : If the function fails or times out, the return value is zero.
1325 To get extended error information, call GetLastError. If GetLastError
1326 returns ERROR_TIMEOUT, then the function timed out.
1328 SetLastWin32Error(ERROR_TIMEOUT
);
1331 else if (! NT_SUCCESS(Status
))
1333 SetLastNtError(Status
);
1340 if (Window
) UserDerefObjectCo(Window
);
1345 co_IntSendMessageTimeout( HWND hWnd
,
1351 ULONG_PTR
*uResult
)
1353 PWINDOW_OBJECT DesktopWindow
;
1357 if (HWND_BROADCAST
!= hWnd
)
1359 return co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1362 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1363 if (NULL
== DesktopWindow
)
1365 SetLastWin32Error(ERROR_INTERNAL_ERROR
);
1369 Children
= IntWinListChildren(DesktopWindow
);
1370 if (NULL
== Children
)
1375 for (Child
= Children
; NULL
!= *Child
; Child
++)
1377 co_IntSendMessageTimeoutSingle(*Child
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1380 ExFreePool(Children
);
1382 return (LRESULT
) TRUE
;
1386 /* This function posts a message if the destination's message queue belongs to
1387 another thread, otherwise it sends the message. It does not support broadcast
1390 co_IntPostOrSendMessage( HWND hWnd
,
1397 PWINDOW_OBJECT Window
;
1399 if ( hWnd
== HWND_BROADCAST
)
1404 if(!(Window
= UserGetWindowObject(hWnd
)))
1409 pti
= PsGetCurrentThreadWin32Thread();
1411 if ( Window
->MessageQueue
!= pti
->MessageQueue
&&
1412 FindMsgMemory(Msg
) == 0 )
1414 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1418 if ( !co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
) )
1424 return (LRESULT
)Result
;
1428 co_IntDoSendMessage( HWND hWnd
,
1433 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1436 LRESULT Result
= TRUE
;
1438 PWINDOW_OBJECT Window
= NULL
;
1439 NTUSERSENDMESSAGEINFO Info
;
1442 PMSGMEMORY MsgMemoryEntry
;
1444 RtlZeroMemory(&Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1446 /* FIXME: Call hooks. */
1447 if (HWND_BROADCAST
!= hWnd
)
1449 Window
= UserGetWindowObject(hWnd
);
1450 if ( !Window
|| !Window
->Wnd
)
1452 /* Tell usermode to not touch this one */
1453 Info
.HandledByKernel
= TRUE
;
1454 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1459 /* Check for an exiting window. */
1460 if (Window
&& Window
->Status
& WINDOWSTATUS_DESTROYING
)
1462 DPRINT1("co_IntDoSendMessage Window Exiting!\n");
1465 /* See if the current thread can handle the message */
1466 pti
= PsGetCurrentThreadWin32Thread();
1468 // This is checked in user mode!!!!!!!
1469 if ( HWND_BROADCAST
!= hWnd
&&
1471 Window
->MessageQueue
== pti
->MessageQueue
&&
1472 !ISITHOOKED(WH_CALLWNDPROC
) &&
1473 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
1474 ( Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
) )
1476 /* Gather the information usermode needs to call the window proc directly */
1477 Info
.HandledByKernel
= FALSE
;
1479 Status
= MmCopyFromCaller(&(Info
.Ansi
), &(UnsafeInfo
->Ansi
),
1481 if (! NT_SUCCESS(Status
))
1483 Info
.Ansi
= ! Window
->Wnd
->Unicode
;
1486 Info
.Ansi
= !Window
->Wnd
->Unicode
;
1487 Info
.Proc
= Window
->Wnd
->lpfnWndProc
;
1491 /* Must be handled by other thread */
1492 // if (HWND_BROADCAST != hWnd)
1494 // UserDereferenceObject(Window);
1496 Info
.HandledByKernel
= TRUE
;
1497 UserModeMsg
.hwnd
= hWnd
;
1498 UserModeMsg
.message
= Msg
;
1499 UserModeMsg
.wParam
= wParam
;
1500 UserModeMsg
.lParam
= lParam
;
1501 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1503 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1504 if (! NT_SUCCESS(Status
))
1506 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1507 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1508 return (dsm
? 0 : -1);
1513 Result
= co_IntSendMessage( KernelModeMsg
.hwnd
,
1514 KernelModeMsg
.message
,
1515 KernelModeMsg
.wParam
,
1516 KernelModeMsg
.lParam
);
1520 Result
= co_IntSendMessageTimeout( KernelModeMsg
.hwnd
,
1521 KernelModeMsg
.message
,
1522 KernelModeMsg
.wParam
,
1523 KernelModeMsg
.lParam
,
1529 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1530 if (! NT_SUCCESS(Status
))
1532 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1533 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1534 return(dsm
? 0 : -1);
1538 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1539 if (! NT_SUCCESS(Status
))
1541 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1544 return (LRESULT
)Result
;
1549 UserSendNotifyMessage( HWND hWnd
,
1556 if (FindMsgMemory(Msg
) != 0)
1558 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1562 // Basicly the same as IntPostOrSendMessage
1563 if (hWnd
== HWND_BROADCAST
) //Handle Broadcast
1566 PWINDOW_OBJECT DesktopWindow
;
1569 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1570 List
= IntWinListChildren(DesktopWindow
);
1574 for (i
= 0; List
[i
]; i
++)
1576 UserSendNotifyMessage(List
[i
], Msg
, wParam
, lParam
);
1585 PWINDOW_OBJECT Window
;
1588 if ( !(Window
= UserGetWindowObject(hWnd
)) ) return FALSE
;
1590 pti
= PsGetCurrentThreadWin32Thread();
1592 if (Window
->MessageQueue
!= pti
->MessageQueue
)
1593 { // Send message w/o waiting for it.
1594 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1597 { // Handle message and callback.
1598 Message
.hwnd
= hWnd
;
1599 Message
.message
= Msg
;
1600 Message
.wParam
= wParam
;
1601 Message
.lParam
= lParam
;
1603 Result
= co_IntSendMessageTimeoutSingle( hWnd
,
1617 IntGetQueueStatus(BOOL ClearChanges
)
1620 PUSER_MESSAGE_QUEUE Queue
;
1622 DECLARE_RETURN(DWORD
);
1624 DPRINT("Enter IntGetQueueStatus\n");
1626 pti
= PsGetCurrentThreadWin32Thread();
1627 Queue
= pti
->MessageQueue
;
1629 Result
= MAKELONG(Queue
->QueueBits
, Queue
->ChangedBits
);
1632 Queue
->ChangedBits
= 0;
1638 DPRINT("Leave IntGetQueueStatus, ret=%i\n",_ret_
);
1643 IntInitMessagePumpHook()
1645 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1647 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
++;
1654 IntUninitMessagePumpHook()
1656 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1658 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
<= 0)
1662 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
--;
1668 /** Functions ******************************************************************/
1671 NtUserPostMessage(HWND hWnd
,
1676 DECLARE_RETURN(BOOL
);
1678 DPRINT("Enter NtUserPostMessage\n");
1679 UserEnterExclusive();
1681 RETURN( UserPostMessage(hWnd
, Msg
, wParam
, lParam
));
1684 DPRINT("Leave NtUserPostMessage, ret=%i\n",_ret_
);
1690 NtUserPostThreadMessage(DWORD idThread
,
1695 DECLARE_RETURN(BOOL
);
1697 DPRINT("Enter NtUserPostThreadMessage\n");
1698 UserEnterExclusive();
1700 RETURN( UserPostThreadMessage( idThread
,
1706 DPRINT("Leave NtUserPostThreadMessage, ret=%i\n",_ret_
);
1712 NtUserQuerySendMessage(DWORD Unknown0
)
1720 ////////// API on the way out!
1722 NtUserSendMessageTimeout( HWND hWnd
,
1729 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1733 DECLARE_RETURN(BOOL
);
1735 DPRINT("Enter NtUserSendMessageTimeout\n");
1736 UserEnterExclusive();
1738 dsm
.uFlags
= uFlags
;
1739 dsm
.uTimeout
= uTimeout
;
1740 Result
= co_IntDoSendMessage(hWnd
, Msg
, wParam
, lParam
, &dsm
, UnsafeInfo
);
1741 if(uResult
!= NULL
&& Result
!= 0)
1745 Status
= MmCopyToCaller(uResult
, &dsm
.Result
, sizeof(ULONG_PTR
));
1746 if(!NT_SUCCESS(Status
))
1748 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1755 DPRINT("Leave NtUserSendMessageTimeout, ret=%i\n",_ret_
);
1761 NtUserSendMessage( HWND Wnd
,
1765 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1767 DECLARE_RETURN(BOOL
);
1769 DPRINT("Enter NtUserSendMessage\n");
1770 UserEnterExclusive();
1772 RETURN(co_IntDoSendMessage(Wnd
, Msg
, wParam
, lParam
, NULL
, UnsafeInfo
));
1775 DPRINT("Leave NtUserSendMessage, ret=%i\n",_ret_
);
1782 NtUserWaitMessage(VOID
)
1784 DECLARE_RETURN(BOOL
);
1786 DPRINT("EnterNtUserWaitMessage\n");
1787 UserEnterExclusive();
1789 RETURN(co_IntWaitMessage(NULL
, 0, 0));
1792 DPRINT("Leave NtUserWaitMessage, ret=%i\n",_ret_
);
1799 NtUserGetMessage( PNTUSERGETMESSAGEINFO UnsafeInfo
,
1804 * FUNCTION: Get a message from the calling thread's message queue.
1806 * UnsafeMsg - Pointer to the structure which receives the returned message.
1807 * Wnd - Window whose messages are to be retrieved.
1808 * MsgFilterMin - Integer value of the lowest message value to be
1810 * MsgFilterMax - Integer value of the highest message value to be
1815 NTUSERGETMESSAGEINFO Info
;
1817 /* FIXME: if initialization is removed, gcc complains that this may be used before initialization. Please review */
1818 PWINDOW_OBJECT Window
= NULL
;
1819 PMSGMEMORY MsgMemoryEntry
;
1823 DECLARE_RETURN(BOOL
);
1824 // USER_REFERENCE_ENTRY Ref;
1826 DPRINT("Enter NtUserGetMessage\n");
1827 UserEnterExclusive();
1829 /* Validate input */
1830 if (hWnd
&& !(Window
= UserGetWindowObject(hWnd
)))
1835 // if (Window) UserRefObjectCo(Window, &Ref);
1837 if (MsgFilterMax
< MsgFilterMin
)
1845 GotMessage
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
);
1849 /* See if this message type is present in the table */
1850 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
1851 if (NULL
== MsgMemoryEntry
)
1853 /* Not present, no copying needed */
1854 Info
.LParamSize
= 0;
1858 /* Determine required size */
1859 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
1861 /* Allocate required amount of user-mode memory */
1862 Info
.LParamSize
= Size
;
1864 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
1865 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
1867 if (! NT_SUCCESS(Status
))
1869 SetLastNtError(Status
);
1872 /* Transfer lParam data to user-mode mem */
1873 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
1874 if (! NT_SUCCESS(Status
))
1876 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
1877 &Info
.LParamSize
, MEM_DECOMMIT
);
1878 SetLastNtError(Status
);
1881 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
1883 if (Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
1885 ExFreePool((void *) Msg
.Msg
.lParam
);
1887 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
1888 if (! NT_SUCCESS(Status
))
1890 SetLastNtError(Status
);
1894 else if (! co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
))
1899 while (! GotMessage
);
1901 RETURN( WM_QUIT
!= Info
.Msg
.message
);
1904 // if (Window) UserDerefObjectCo(Window);
1906 DPRINT("Leave NtUserGetMessage\n");
1922 DECLARE_RETURN(BOOL
);
1924 DPRINT("Enter NtUserGetMessage\n");
1925 UserEnterExclusive();
1927 if ( (MsgFilterMin
|MsgFilterMax
) & ~WM_MAXIMUM
)
1929 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1933 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
, TRUE
);
1939 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
1940 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
1942 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1944 SetLastNtError(_SEH2_GetExceptionCode());
1952 DPRINT("Leave NtUserGetMessage\n");
1958 NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
1966 NTUSERGETMESSAGEINFO Info
;
1967 PWINDOW_OBJECT Window
;
1968 PMSGMEMORY MsgMemoryEntry
;
1972 DECLARE_RETURN(BOOL
);
1974 DPRINT("Enter NtUserPeekMessage\n");
1975 UserEnterExclusive();
1977 if (hWnd
== (HWND
)-1 || hWnd
== (HWND
)0x0000FFFF || hWnd
== (HWND
)0xFFFFFFFF)
1980 /* Validate input */
1981 if (hWnd
&& hWnd
!= (HWND
)1)
1983 if (!(Window
= UserGetWindowObject(hWnd
)))
1990 Window
= (PWINDOW_OBJECT
)hWnd
;
1993 if (MsgFilterMax
< MsgFilterMin
)
1999 Present
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
);
2004 /* See if this message type is present in the table */
2005 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
2006 if (NULL
== MsgMemoryEntry
)
2008 /* Not present, no copying needed */
2009 Info
.LParamSize
= 0;
2013 /* Determine required size */
2014 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
2016 /* Allocate required amount of user-mode memory */
2017 Info
.LParamSize
= Size
;
2019 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
2020 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
2021 if (! NT_SUCCESS(Status
))
2023 SetLastNtError(Status
);
2026 /* Transfer lParam data to user-mode mem */
2027 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
2028 if (! NT_SUCCESS(Status
))
2030 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
2031 &Info
.LParamSize
, MEM_RELEASE
);
2032 SetLastNtError(Status
);
2035 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
2037 if (RemoveMsg
&& Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
2039 ExFreePool((void *) Msg
.Msg
.lParam
);
2041 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
2042 if (! NT_SUCCESS(Status
))
2044 SetLastNtError(Status
);
2052 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2068 DECLARE_RETURN(BOOL
);
2070 DPRINT("Enter NtUserPeekMessage\n");
2071 UserEnterExclusive();
2073 if ( RemoveMsg
& PM_BADMSGFLAGS
)
2075 SetLastWin32Error(ERROR_INVALID_FLAGS
);
2079 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
, FALSE
);
2085 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
2086 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
2088 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2090 SetLastNtError(_SEH2_GetExceptionCode());
2098 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2105 NtUserCallMsgFilter(
2109 BOOL BadChk
= FALSE
, Ret
= FALSE
;
2111 DECLARE_RETURN(BOOL
);
2113 DPRINT("Enter NtUserCallMsgFilter\n");
2114 UserEnterExclusive();
2119 ProbeForRead((PVOID
)lpmsg
,
2122 RtlCopyMemory( &Msg
,
2126 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2135 if (BadChk
) RETURN( FALSE
);
2137 if ( ISITHOOKED(WH_SYSMSGFILTER
) &&
2138 co_HOOK_CallHooks( WH_SYSMSGFILTER
, code
, 0, (LPARAM
)&Msg
))
2144 if ( ISITHOOKED(WH_MSGFILTER
) )
2146 Ret
= co_HOOK_CallHooks( WH_MSGFILTER
, code
, 0, (LPARAM
)&Msg
);
2152 ProbeForWrite((PVOID
)lpmsg
,
2155 RtlCopyMemory((PVOID
)lpmsg
,
2159 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2164 if (BadChk
) RETURN( FALSE
);
2168 DPRINT("Leave NtUserCallMsgFilter. ret=%i\n", _ret_
);
2174 NtUserDispatchMessage(PMSG UnsafeMsgInfo
)
2180 UserEnterExclusive();
2183 ProbeForRead(UnsafeMsgInfo
, sizeof(MSG
), 1);
2184 RtlCopyMemory(&SafeMsg
, UnsafeMsgInfo
, sizeof(MSG
));
2186 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2188 SetLastNtError(_SEH2_GetExceptionCode());
2193 if (!Hit
) Res
= IntDispatchMessage(&SafeMsg
);
2201 NtUserTranslateMessage(LPMSG lpMsg
,
2206 DECLARE_RETURN(BOOL
);
2208 DPRINT("Enter NtUserTranslateMessage\n");
2209 UserEnterExclusive();
2211 Status
= MmCopyFromCaller(&SafeMsg
, lpMsg
, sizeof(MSG
));
2212 if(!NT_SUCCESS(Status
))
2214 SetLastNtError(Status
);
2218 RETURN( IntTranslateKbdMessage(&SafeMsg
, dwhkl
));
2221 DPRINT("Leave NtUserTranslateMessage: ret=%i\n",_ret_
);
2232 ULONG_PTR ResultInfo
,
2233 DWORD dwType
, // fnID?
2236 LRESULT lResult
= 0;
2238 BOOL BadChk
= FALSE
;
2239 PWINDOW_OBJECT Window
= NULL
;
2240 USER_REFERENCE_ENTRY Ref
;
2242 UserEnterExclusive();
2244 /* Validate input */
2245 if (hWnd
&& (hWnd
!= INVALID_HANDLE_VALUE
) && !(Window
= UserGetWindowObject(hWnd
)))
2252 case FNID_DEFWINDOWPROC
:
2253 UserRefObjectCo(Window
, &Ref
);
2254 lResult
= IntDefWindowProc(Window
, Msg
, wParam
, lParam
, Ansi
);
2256 UserDerefObjectCo(Window
);
2258 case FNID_SENDNOTIFYMESSAGE
:
2259 Ret
= UserSendNotifyMessage(hWnd
, Msg
, wParam
, lParam
);
2261 case FNID_BROADCASTSYSTEMMESSAGE
:
2264 DWORD_PTR RetVal
= 0;
2270 ProbeForWrite((PVOID
)ResultInfo
,
2271 sizeof(BROADCASTPARM
),
2273 RtlCopyMemory(&parm
, (PVOID
)ResultInfo
, sizeof(BROADCASTPARM
));
2275 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2285 if ( parm
.recipients
& BSM_ALLDESKTOPS
||
2286 parm
.recipients
== BSM_ALLCOMPONENTS
)
2289 else if (parm
.recipients
& BSM_APPLICATIONS
)
2291 if (parm
.flags
& BSF_QUERY
)
2293 if (parm
.flags
& BSF_FORCEIFHUNG
|| parm
.flags
& BSF_NOHANG
)
2295 co_IntSendMessageTimeout( HWND_BROADCAST
,
2303 else if (parm
.flags
& BSF_NOTIMEOUTIFNOTHUNG
)
2305 co_IntSendMessageTimeout( HWND_BROADCAST
,
2309 SMTO_NOTIMEOUTIFNOTHUNG
,
2315 co_IntSendMessageTimeout( HWND_BROADCAST
,
2324 else if (parm
.flags
& BSF_POSTMESSAGE
)
2326 Ret
= UserPostMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2328 else if ( parm
.flags
& BSF_SENDNOTIFYMESSAGE
)
2330 Ret
= UserSendNotifyMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2335 case FNID_SENDMESSAGECALLBACK
:
2337 // CallNextHook bypass.
2338 case FNID_CALLWNDPROC
:
2339 case FNID_CALLWNDPROCRET
:
2341 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
2342 PHOOK NextObj
, Hook
= ClientInfo
->phkCurrent
;
2344 if (!ClientInfo
|| !Hook
) break;
2346 UserReferenceObject(Hook
);
2348 if (Hook
->Thread
&& (Hook
->Thread
!= PsGetCurrentThread()))
2350 UserDereferenceObject(Hook
);
2354 NextObj
= IntGetNextHook(Hook
);
2355 ClientInfo
->phkCurrent
= NextObj
;
2357 if ( Hook
->HookId
== WH_CALLWNDPROC
)
2362 CWP
.wParam
= wParam
;
2363 CWP
.lParam
= lParam
;
2364 DPRINT("WH_CALLWNDPROC: Hook %x NextHook %x\n", Hook
, NextObj
);
2366 lResult
= co_IntCallHookProc( Hook
->HookId
,
2368 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2379 CWPR
.wParam
= wParam
;
2380 CWPR
.lParam
= lParam
;
2381 CWPR
.lResult
= ClientInfo
->dwHookData
;
2383 lResult
= co_IntCallHookProc( Hook
->HookId
,
2385 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2391 UserDereferenceObject(Hook
);
2392 lResult
= (LRESULT
) NextObj
;
2399 case FNID_DEFWINDOWPROC
:
2400 case FNID_CALLWNDPROC
:
2401 case FNID_CALLWNDPROCRET
:
2406 ProbeForWrite((PVOID
)ResultInfo
, sizeof(LRESULT
), 1);
2407 RtlCopyMemory((PVOID
)ResultInfo
, &lResult
, sizeof(LRESULT
));
2409 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2422 return BadChk
? FALSE
: Ret
;
2425 #define INFINITE 0xFFFFFFFF
2426 #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
2430 NtUserWaitForInputIdle(
2432 IN DWORD dwMilliseconds
,
2436 PPROCESSINFO W32Process
;
2439 LARGE_INTEGER Timeout
;
2440 ULONGLONG StartTime
, Run
, Elapsed
= 0;
2442 UserEnterExclusive();
2444 Status
= ObReferenceObjectByHandle(hProcess
,
2445 PROCESS_QUERY_INFORMATION
,
2451 if (!NT_SUCCESS(Status
))
2454 SetLastNtError(Status
);
2458 W32Process
= (PPROCESSINFO
)Process
->Win32Process
;
2461 ObDereferenceObject(Process
);
2463 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2467 EngCreateEvent((PEVENT
*)&W32Process
->InputIdleEvent
);
2469 Handles
[0] = Process
;
2470 Handles
[1] = W32Process
->InputIdleEvent
;
2474 ObDereferenceObject(Process
);
2476 return STATUS_SUCCESS
; /* no event to wait on */
2479 StartTime
= EngGetTickCount();
2481 Run
= dwMilliseconds
;
2483 DPRINT("WFII: waiting for %p\n", Handles
[1] );
2486 Timeout
.QuadPart
= Run
- Elapsed
;
2488 Status
= KeWaitForMultipleObjects( 2,
2494 dwMilliseconds
== INFINITE
? NULL
: &Timeout
,
2496 UserEnterExclusive();
2498 if (!NT_SUCCESS(Status
))
2500 SetLastNtError(Status
);
2501 Status
= WAIT_FAILED
;
2508 Status
= WAIT_FAILED
;
2514 co_IntPeekMessage( &Msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2518 case STATUS_USER_APC
:
2519 case STATUS_ALERTED
:
2520 case STATUS_TIMEOUT
:
2521 DPRINT1("WFII: timeout\n");
2522 Status
= STATUS_TIMEOUT
;
2526 DPRINT1("WFII: finished\n");
2527 Status
= STATUS_SUCCESS
;
2531 if (dwMilliseconds
!= INFINITE
)
2533 Elapsed
= EngGetTickCount() - StartTime
;
2536 Status
= STATUS_TIMEOUT
;
2543 if (W32Process
->InputIdleEvent
)
2545 EngDeleteEvent((PEVENT
)W32Process
->InputIdleEvent
);
2546 W32Process
->InputIdleEvent
= NULL
;
2548 ObDereferenceObject(Process
);