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 ******************************************************************/
24 DOSENDMESSAGE
, *PDOSENDMESSAGE
;
26 /* FUNCTIONS *****************************************************************/
29 IntInitMessageImpl(VOID
)
31 return STATUS_SUCCESS
;
35 IntCleanupMessageImpl(VOID
)
37 return STATUS_SUCCESS
;
40 #define MMS_SIZE_WPARAM -1
41 #define MMS_SIZE_WPARAMWCHAR -2
42 #define MMS_SIZE_LPARAMSZ -3
43 #define MMS_SIZE_SPECIAL -4
44 #define MMS_FLAG_READ 0x01
45 #define MMS_FLAG_WRITE 0x02
46 #define MMS_FLAG_READWRITE (MMS_FLAG_READ | MMS_FLAG_WRITE)
47 typedef struct tagMSGMEMORY
53 MSGMEMORY
, *PMSGMEMORY
;
55 static MSGMEMORY MsgMemory
[] =
57 { WM_CREATE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
58 { WM_DDE_ACK
, sizeof(KMDDELPARAM
), MMS_FLAG_READ
},
59 { WM_DDE_EXECUTE
, MMS_SIZE_WPARAM
, MMS_FLAG_READ
},
60 { WM_GETMINMAXINFO
, sizeof(MINMAXINFO
), MMS_FLAG_READWRITE
},
61 { WM_GETTEXT
, MMS_SIZE_WPARAMWCHAR
, MMS_FLAG_WRITE
},
62 { WM_NCCALCSIZE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
63 { WM_NCCREATE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
64 { WM_SETTEXT
, MMS_SIZE_LPARAMSZ
, MMS_FLAG_READ
},
65 { WM_STYLECHANGED
, sizeof(STYLESTRUCT
), MMS_FLAG_READ
},
66 { WM_STYLECHANGING
, sizeof(STYLESTRUCT
), MMS_FLAG_READWRITE
},
67 { WM_COPYDATA
, MMS_SIZE_SPECIAL
, MMS_FLAG_READ
},
68 { WM_WINDOWPOSCHANGED
, sizeof(WINDOWPOS
), MMS_FLAG_READ
},
69 { WM_WINDOWPOSCHANGING
, sizeof(WINDOWPOS
), MMS_FLAG_READWRITE
},
72 static PMSGMEMORY FASTCALL
73 FindMsgMemory(UINT Msg
)
75 PMSGMEMORY MsgMemoryEntry
;
77 /* See if this message type is present in the table */
78 for (MsgMemoryEntry
= MsgMemory
;
79 MsgMemoryEntry
< MsgMemory
+ sizeof(MsgMemory
) / sizeof(MSGMEMORY
);
82 if (Msg
== MsgMemoryEntry
->Message
)
84 return MsgMemoryEntry
;
92 MsgMemorySize(PMSGMEMORY MsgMemoryEntry
, WPARAM wParam
, LPARAM lParam
)
95 PUNICODE_STRING WindowName
;
96 PUNICODE_STRING ClassName
;
101 if (MMS_SIZE_WPARAM
== MsgMemoryEntry
->Size
)
105 else if (MMS_SIZE_WPARAMWCHAR
== MsgMemoryEntry
->Size
)
107 Size
= (UINT
) (wParam
* sizeof(WCHAR
));
109 else if (MMS_SIZE_LPARAMSZ
== MsgMemoryEntry
->Size
)
111 Size
= (UINT
) ((wcslen((PWSTR
) lParam
) + 1) * sizeof(WCHAR
));
113 else if (MMS_SIZE_SPECIAL
== MsgMemoryEntry
->Size
)
115 switch(MsgMemoryEntry
->Message
)
119 Cs
= (CREATESTRUCTW
*) lParam
;
120 WindowName
= (PUNICODE_STRING
) Cs
->lpszName
;
121 ClassName
= (PUNICODE_STRING
) Cs
->lpszClass
;
122 Size
= sizeof(CREATESTRUCTW
) + WindowName
->Length
+ sizeof(WCHAR
);
123 if (IS_ATOM(ClassName
->Buffer
))
125 Size
+= sizeof(WCHAR
) + sizeof(ATOM
);
129 Size
+= sizeof(WCHAR
) + ClassName
->Length
+ sizeof(WCHAR
);
134 Size
= wParam
? sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
) : sizeof(RECT
);
138 Size
= sizeof(COPYDATASTRUCT
) + ((PCOPYDATASTRUCT
)lParam
)->cbData
;
141 case WM_COPYGLOBALDATA
:
153 Size
= MsgMemoryEntry
->Size
;
156 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
158 DPRINT1("Exception caught in MsgMemorySize()! Status: 0x%x\n", _SEH2_GetExceptionCode());
166 PackParam(LPARAM
*lParamPacked
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
168 NCCALCSIZE_PARAMS
*UnpackedNcCalcsize
;
169 NCCALCSIZE_PARAMS
*PackedNcCalcsize
;
170 CREATESTRUCTW
*UnpackedCs
;
171 CREATESTRUCTW
*PackedCs
;
172 PUNICODE_STRING WindowName
;
173 PUNICODE_STRING ClassName
;
177 *lParamPacked
= lParam
;
178 if (WM_NCCALCSIZE
== Msg
&& wParam
)
180 UnpackedNcCalcsize
= (NCCALCSIZE_PARAMS
*) lParam
;
181 if (UnpackedNcCalcsize
->lppos
!= (PWINDOWPOS
) (UnpackedNcCalcsize
+ 1))
183 PackedNcCalcsize
= ExAllocatePoolWithTag(PagedPool
,
184 sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
),
186 if (NULL
== PackedNcCalcsize
)
188 DPRINT1("Not enough memory to pack lParam\n");
189 return STATUS_NO_MEMORY
;
191 RtlCopyMemory(PackedNcCalcsize
, UnpackedNcCalcsize
, sizeof(NCCALCSIZE_PARAMS
));
192 PackedNcCalcsize
->lppos
= (PWINDOWPOS
) (PackedNcCalcsize
+ 1);
193 RtlCopyMemory(PackedNcCalcsize
->lppos
, UnpackedNcCalcsize
->lppos
, sizeof(WINDOWPOS
));
194 *lParamPacked
= (LPARAM
) PackedNcCalcsize
;
197 else if (WM_CREATE
== Msg
|| WM_NCCREATE
== Msg
)
199 UnpackedCs
= (CREATESTRUCTW
*) lParam
;
200 WindowName
= (PUNICODE_STRING
) UnpackedCs
->lpszName
;
201 ClassName
= (PUNICODE_STRING
) UnpackedCs
->lpszClass
;
202 Size
= sizeof(CREATESTRUCTW
) + WindowName
->Length
+ sizeof(WCHAR
);
203 if (IS_ATOM(ClassName
->Buffer
))
205 Size
+= sizeof(WCHAR
) + sizeof(ATOM
);
209 Size
+= sizeof(WCHAR
) + ClassName
->Length
+ sizeof(WCHAR
);
211 PackedCs
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
212 if (NULL
== PackedCs
)
214 DPRINT1("Not enough memory to pack lParam\n");
215 return STATUS_NO_MEMORY
;
217 RtlCopyMemory(PackedCs
, UnpackedCs
, sizeof(CREATESTRUCTW
));
218 CsData
= (PCHAR
) (PackedCs
+ 1);
219 PackedCs
->lpszName
= (LPCWSTR
) (CsData
- (PCHAR
) PackedCs
);
220 RtlCopyMemory(CsData
, WindowName
->Buffer
, WindowName
->Length
);
221 CsData
+= WindowName
->Length
;
222 *((WCHAR
*) CsData
) = L
'\0';
223 CsData
+= sizeof(WCHAR
);
224 PackedCs
->lpszClass
= (LPCWSTR
) (CsData
- (PCHAR
) PackedCs
);
225 if (IS_ATOM(ClassName
->Buffer
))
227 *((WCHAR
*) CsData
) = L
'A';
228 CsData
+= sizeof(WCHAR
);
229 *((ATOM
*) CsData
) = (ATOM
)(DWORD_PTR
) ClassName
->Buffer
;
230 CsData
+= sizeof(ATOM
);
234 *((WCHAR
*) CsData
) = L
'S';
235 CsData
+= sizeof(WCHAR
);
236 RtlCopyMemory(CsData
, ClassName
->Buffer
, ClassName
->Length
);
237 CsData
+= ClassName
->Length
;
238 *((WCHAR
*) CsData
) = L
'\0';
239 CsData
+= sizeof(WCHAR
);
241 ASSERT(CsData
== (PCHAR
) PackedCs
+ Size
);
242 *lParamPacked
= (LPARAM
) PackedCs
;
245 return STATUS_SUCCESS
;
249 UnpackParam(LPARAM lParamPacked
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
251 NCCALCSIZE_PARAMS
*UnpackedParams
;
252 NCCALCSIZE_PARAMS
*PackedParams
;
253 PWINDOWPOS UnpackedWindowPos
;
255 if (lParamPacked
== lParam
)
257 return STATUS_SUCCESS
;
260 if (WM_NCCALCSIZE
== Msg
&& wParam
)
262 PackedParams
= (NCCALCSIZE_PARAMS
*) lParamPacked
;
263 UnpackedParams
= (NCCALCSIZE_PARAMS
*) lParam
;
264 UnpackedWindowPos
= UnpackedParams
->lppos
;
265 RtlCopyMemory(UnpackedParams
, PackedParams
, sizeof(NCCALCSIZE_PARAMS
));
266 UnpackedParams
->lppos
= UnpackedWindowPos
;
267 RtlCopyMemory(UnpackedWindowPos
, PackedParams
+ 1, sizeof(WINDOWPOS
));
268 ExFreePool((PVOID
) lParamPacked
);
270 return STATUS_SUCCESS
;
272 else if (WM_CREATE
== Msg
|| WM_NCCREATE
== Msg
)
274 ExFreePool((PVOID
) lParamPacked
);
276 return STATUS_SUCCESS
;
281 return STATUS_INVALID_PARAMETER
;
288 ( PWINDOW_OBJECT Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
290 BOOL SameThread
= FALSE
;
292 if (Window
->ti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
295 if ((!SameThread
&& (Window
->ti
->fsHooks
& HOOKID_TO_FLAG(WH_CALLWNDPROC
))) ||
296 (SameThread
&& ISITHOOKED(WH_CALLWNDPROC
)) )
303 co_HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, SameThread
, (LPARAM
)&CWP
);
310 ( PWINDOW_OBJECT Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*uResult
)
312 BOOL SameThread
= FALSE
;
314 if (Window
->ti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
317 if ((!SameThread
&& (Window
->ti
->fsHooks
& HOOKID_TO_FLAG(WH_CALLWNDPROCRET
))) ||
318 (SameThread
&& ISITHOOKED(WH_CALLWNDPROCRET
)) )
323 CWPR
.wParam
= wParam
;
324 CWPR
.lParam
= lParam
;
325 CWPR
.lResult
= *uResult
;
326 co_HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, SameThread
, (LPARAM
)&CWPR
);
332 IntDispatchMessage(PMSG pMsg
)
334 LARGE_INTEGER TickCount
;
337 PWINDOW_OBJECT Window
= NULL
;
341 Window
= UserGetWindowObject(pMsg
->hwnd
);
342 if (!Window
|| !Window
->Wnd
) return 0;
345 if (((pMsg
->message
== WM_SYSTIMER
) ||
346 (pMsg
->message
== WM_TIMER
)) &&
349 if (pMsg
->message
== WM_TIMER
)
351 if (ValidateTimerCallback(PsGetCurrentThreadWin32Thread(),Window
,pMsg
->wParam
,pMsg
->lParam
))
353 KeQueryTickCount(&TickCount
);
354 Time
= MsqCalculateMessageTime(&TickCount
);
355 return co_IntCallWindowProc((WNDPROC
)pMsg
->lParam
,
367 PTIMER pTimer
= FindSystemTimer(pMsg
);
368 if (pTimer
&& pTimer
->pfn
)
370 KeQueryTickCount(&TickCount
);
371 Time
= MsqCalculateMessageTime(&TickCount
);
372 pTimer
->pfn(pMsg
->hwnd
, WM_SYSTIMER
, (UINT
)pMsg
->wParam
, Time
);
378 if (!Window
) return 0;
380 retval
= co_IntPostOrSendMessage(pMsg
->hwnd
, pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
382 if (pMsg
->message
== WM_PAINT
)
384 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
385 HRGN hrgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
386 co_UserGetUpdateRgn( Window
, hrgn
, TRUE
);
387 GreDeleteObject( hrgn
);
399 BOOL BadChk
= FALSE
, Ret
= TRUE
;
401 DECLARE_RETURN(BOOL
);
403 DPRINT("Enter NtUserCallMsgFilter\n");
404 UserEnterExclusive();
409 ProbeForRead((PVOID
)lpmsg
,
416 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
425 if (BadChk
) RETURN( FALSE
);
427 if (!co_HOOK_CallHooks( WH_SYSMSGFILTER
, code
, 0, (LPARAM
)&Msg
))
429 Ret
= co_HOOK_CallHooks( WH_MSGFILTER
, code
, 0, (LPARAM
)&Msg
);
434 ProbeForWrite((PVOID
)lpmsg
,
437 RtlCopyMemory((PVOID
)lpmsg
,
441 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
446 if (BadChk
) RETURN( FALSE
);
450 DPRINT("Leave NtUserCallMsgFilter. ret=%i\n", _ret_
);
456 NtUserDispatchMessage(PMSG UnsafeMsgInfo
)
462 UserEnterExclusive();
465 ProbeForRead(UnsafeMsgInfo
, sizeof(MSG
), 1);
466 RtlCopyMemory(&SafeMsg
, UnsafeMsgInfo
, sizeof(MSG
));
468 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
470 SetLastNtError(_SEH2_GetExceptionCode());
475 if (!Hit
) Res
= IntDispatchMessage(&SafeMsg
);
483 NtUserTranslateMessage(LPMSG lpMsg
,
488 DECLARE_RETURN(BOOL
);
490 DPRINT("Enter NtUserTranslateMessage\n");
491 UserEnterExclusive();
493 Status
= MmCopyFromCaller(&SafeMsg
, lpMsg
, sizeof(MSG
));
494 if(!NT_SUCCESS(Status
))
496 SetLastNtError(Status
);
500 RETURN( IntTranslateKbdMessage(&SafeMsg
, dwhkl
));
503 DPRINT("Leave NtUserTranslateMessage: ret=%i\n",_ret_
);
510 co_IntSendHitTestMessages(PUSER_MESSAGE_QUEUE ThreadQueue
, LPMSG Msg
)
512 if(!Msg
->hwnd
|| ThreadQueue
->CaptureWindow
)
521 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
526 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
533 case WM_LBUTTONDBLCLK
:
534 case WM_MBUTTONDBLCLK
:
535 case WM_RBUTTONDBLCLK
:
536 case WM_XBUTTONDBLCLK
:
539 PSYSTEM_CURSORINFO CurInfo
;
541 if(!IntGetWindowStationObject(InputWindowStation
))
545 CurInfo
= IntGetSysCursorInfo(InputWindowStation
);
546 wParam
= (WPARAM
)(CurInfo
->ButtonsDown
);
547 ObDereferenceObject(InputWindowStation
);
549 co_IntSendMessage(Msg
->hwnd
, WM_MOUSEMOVE
, wParam
, Msg
->lParam
);
550 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
553 case WM_NCLBUTTONDOWN
:
554 case WM_NCMBUTTONDOWN
:
555 case WM_NCRBUTTONDOWN
:
556 case WM_NCXBUTTONDOWN
:
557 case WM_NCLBUTTONDBLCLK
:
558 case WM_NCMBUTTONDBLCLK
:
559 case WM_NCRBUTTONDBLCLK
:
560 case WM_NCXBUTTONDBLCLK
:
562 co_IntSendMessage(Msg
->hwnd
, WM_NCMOUSEMOVE
, (WPARAM
)Msg
->wParam
, Msg
->lParam
);
563 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
570 co_IntActivateWindowMouse(PUSER_MESSAGE_QUEUE ThreadQueue
, LPMSG Msg
, PWINDOW_OBJECT MsgWindow
,
574 PWINDOW_OBJECT Parent
;
576 ASSERT_REFS_CO(MsgWindow
);
578 if(*HitTest
== (USHORT
)HTTRANSPARENT
)
580 /* eat the message, search again! */
584 Parent
= IntGetParent(MsgWindow
);//fixme: deref retval?
586 /* If no parent window, pass MsgWindows HWND as wParam. Fixes bug #3111 */
587 Result
= co_IntSendMessage(MsgWindow
->hSelf
,
589 (WPARAM
) (Parent
? Parent
->hSelf
: MsgWindow
->hSelf
),
590 (LPARAM
)MAKELONG(*HitTest
, Msg
->message
)
595 case MA_NOACTIVATEANDEAT
:
599 case MA_ACTIVATEANDEAT
:
600 co_IntMouseActivateWindow(MsgWindow
);
604 co_IntMouseActivateWindow(MsgWindow
);
612 co_IntTranslateMouseMessage(PUSER_MESSAGE_QUEUE ThreadQueue
, LPMSG Msg
, USHORT
*HitTest
, BOOL Remove
)
614 PWINDOW_OBJECT Window
;
615 USER_REFERENCE_ENTRY Ref
, DesktopRef
;
617 if(!(Window
= UserGetWindowObject(Msg
->hwnd
)))
619 /* let's just eat the message?! */
623 UserRefObjectCo(Window
, &Ref
);
625 if(ThreadQueue
== Window
->MessageQueue
&&
626 ThreadQueue
->CaptureWindow
!= Window
->hSelf
)
628 /* only send WM_NCHITTEST messages if we're not capturing the window! */
629 *HitTest
= co_IntSendMessage(Window
->hSelf
, WM_NCHITTEST
, 0,
630 MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
));
632 if(*HitTest
== (USHORT
)HTTRANSPARENT
)
634 PWINDOW_OBJECT DesktopWindow
;
635 HWND hDesktop
= IntGetDesktopWindow();
637 if((DesktopWindow
= UserGetWindowObject(hDesktop
)))
641 UserRefObjectCo(DesktopWindow
, &DesktopRef
);
643 co_WinPosWindowFromPoint(DesktopWindow
, Window
->MessageQueue
, &Msg
->pt
, &Wnd
);
648 /* post the message to the other window */
649 Msg
->hwnd
= Wnd
->hSelf
;
650 if(!(Wnd
->Status
& WINDOWSTATUS_DESTROYING
))
652 MsqPostMessage(Wnd
->MessageQueue
, Msg
, FALSE
,
653 Msg
->message
== WM_MOUSEMOVE
? QS_MOUSEMOVE
:
657 /* eat the message */
658 UserDereferenceObject(Wnd
);
659 UserDerefObjectCo(DesktopWindow
);
660 UserDerefObjectCo(Window
);
663 UserDereferenceObject(Wnd
);
666 UserDerefObjectCo(DesktopWindow
);
675 if(IS_BTN_MESSAGE(Msg
->message
, DOWN
))
677 /* generate double click messages, if necessary */
678 if ((((*HitTest
) != HTCLIENT
) ||
679 (Window
->Wnd
->pcls
->style
& CS_DBLCLKS
)) &&
680 MsqIsDblClk(Msg
, Remove
))
682 Msg
->message
+= WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
;
686 if(Msg
->message
!= WM_MOUSEWHEEL
)
689 if ((*HitTest
) != HTCLIENT
)
691 Msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
692 if((Msg
->message
== WM_NCRBUTTONUP
) &&
693 (((*HitTest
) == HTCAPTION
) || ((*HitTest
) == HTSYSMENU
)))
695 Msg
->message
= WM_CONTEXTMENU
;
696 Msg
->wParam
= (WPARAM
)Window
->hSelf
;
700 Msg
->wParam
= *HitTest
;
702 Msg
->lParam
= MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
);
704 else if(ThreadQueue
->MoveSize
== NULL
&&
705 ThreadQueue
->MenuOwner
== NULL
)
707 /* NOTE: Msg->pt should remain in screen coordinates. -- FiN */
708 Msg
->lParam
= MAKELONG(
709 Msg
->pt
.x
- (WORD
)Window
->Wnd
->rcClient
.left
,
710 Msg
->pt
.y
- (WORD
)Window
->Wnd
->rcClient
.top
);
714 UserDerefObjectCo(Window
);
720 * Internal version of PeekMessage() doing all the work
723 co_IntPeekMessage(PUSER_MESSAGE Msg
,
724 PWINDOW_OBJECT Window
,
730 LARGE_INTEGER LargeTickCount
;
731 PUSER_MESSAGE_QUEUE ThreadQueue
;
732 PUSER_MESSAGE Message
;
733 BOOL Present
, RemoveMessages
;
734 USER_REFERENCE_ENTRY Ref
;
736 MOUSEHOOKSTRUCT MHook
;
738 /* The queues and order in which they are checked are documented in the MSDN
739 article on GetMessage() */
741 pti
= PsGetCurrentThreadWin32Thread();
742 ThreadQueue
= pti
->MessageQueue
;
744 /* Inspect RemoveMsg flags */
745 /* FIXME: The only flag we process is PM_REMOVE - processing of others must still be implemented */
746 RemoveMessages
= RemoveMsg
& PM_REMOVE
;
752 KeQueryTickCount(&LargeTickCount
);
753 ThreadQueue
->LastMsgRead
= LargeTickCount
.u
.LowPart
;
755 /* Dispatch sent messages here. */
756 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
759 /* Now look for a quit message. */
761 if (ThreadQueue
->QuitPosted
)
763 /* According to the PSDK, WM_QUIT messages are always returned, regardless
764 of the filter specified */
765 Msg
->Msg
.hwnd
= NULL
;
766 Msg
->Msg
.message
= WM_QUIT
;
767 Msg
->Msg
.wParam
= ThreadQueue
->QuitExitCode
;
769 Msg
->FreeLParam
= FALSE
;
772 ThreadQueue
->QuitPosted
= FALSE
;
777 /* Now check for normal messages. */
778 Present
= co_MsqFindMessage(ThreadQueue
,
787 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
790 MsqDestroyMessage(Message
);
795 /* Check for hardware events. */
796 Present
= co_MsqFindMessage(ThreadQueue
,
805 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
808 MsqDestroyMessage(Message
);
813 /* Check for sent messages again. */
814 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
817 /* Check for paint messages. */
818 if (IntGetPaintMessage(Window
, MsgFilterMin
, MsgFilterMax
, pti
, &Msg
->Msg
, RemoveMessages
))
820 Msg
->FreeLParam
= FALSE
;
824 if (ThreadQueue
->WakeMask
& QS_TIMER
)
825 if (PostTimerMessages(Window
)) // If there are timers ready,
826 goto CheckMessages
; // go back and process them.
828 // LOL! Polling Timer Queue? How much time is spent doing this?
829 /* Check for WM_(SYS)TIMER messages */
830 Present
= MsqGetTimerMessage(ThreadQueue
, Window
, MsgFilterMin
, MsgFilterMax
,
831 &Msg
->Msg
, RemoveMessages
);
834 Msg
->FreeLParam
= FALSE
;
844 PWINDOW_OBJECT MsgWindow
= NULL
;
846 if(Msg
->Msg
.hwnd
&& (MsgWindow
= UserGetWindowObject(Msg
->Msg
.hwnd
)) &&
847 Msg
->Msg
.message
>= WM_MOUSEFIRST
&& Msg
->Msg
.message
<= WM_MOUSELAST
)
851 UserRefObjectCo(MsgWindow
, &Ref
);
853 if(co_IntTranslateMouseMessage(ThreadQueue
, &Msg
->Msg
, &HitTest
, TRUE
))
854 /* FIXME - check message filter again, if the message doesn't match anymore,
857 UserDerefObjectCo(MsgWindow
);
858 /* eat the message, search again */
862 if(ThreadQueue
->CaptureWindow
== NULL
)
864 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
865 if((Msg
->Msg
.message
!= WM_MOUSEMOVE
&& Msg
->Msg
.message
!= WM_NCMOUSEMOVE
) &&
866 IS_BTN_MESSAGE(Msg
->Msg
.message
, DOWN
) &&
867 co_IntActivateWindowMouse(ThreadQueue
, &Msg
->Msg
, MsgWindow
, &HitTest
))
869 UserDerefObjectCo(MsgWindow
);
870 /* eat the message, search again */
875 UserDerefObjectCo(MsgWindow
);
879 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
884 // UserDereferenceObject(MsgWindow);
890 if((Msg
->Msg
.hwnd
&& Msg
->Msg
.message
>= WM_MOUSEFIRST
&& Msg
->Msg
.message
<= WM_MOUSELAST
) &&
891 co_IntTranslateMouseMessage(ThreadQueue
, &Msg
->Msg
, &HitTest
, FALSE
))
892 /* FIXME - check message filter again, if the message doesn't match anymore,
895 /* eat the message, search again */
899 if ( ISITHOOKED(WH_MOUSE
) &&
900 Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
901 Msg
->Msg
.message
<= WM_MOUSELAST
)
903 MHook
.pt
= Msg
->Msg
.pt
;
904 MHook
.hwnd
= Msg
->Msg
.hwnd
;
905 MHook
.wHitTestCode
= HitTest
;
906 MHook
.dwExtraInfo
= 0;
907 if (co_HOOK_CallHooks( WH_MOUSE
,
908 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
912 if (ISITHOOKED(WH_CBT
))
914 MHook
.pt
= Msg
->Msg
.pt
;
915 MHook
.hwnd
= Msg
->Msg
.hwnd
;
916 MHook
.wHitTestCode
= HitTest
;
917 MHook
.dwExtraInfo
= 0;
918 co_HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
,
919 Msg
->Msg
.message
, (LPARAM
)&MHook
);
924 if ( ISITHOOKED(WH_KEYBOARD
) &&
925 (Msg
->Msg
.message
== WM_KEYDOWN
|| Msg
->Msg
.message
== WM_KEYUP
) )
927 if (co_HOOK_CallHooks( WH_KEYBOARD
,
928 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
929 LOWORD(Msg
->Msg
.wParam
),
932 if (ISITHOOKED(WH_CBT
))
934 /* skip this message */
935 co_HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
,
936 LOWORD(Msg
->Msg
.wParam
), Msg
->Msg
.lParam
);
941 // The WH_GETMESSAGE hook enables an application to monitor messages about to
942 // be returned by the GetMessage or PeekMessage function.
943 if (ISITHOOKED(WH_GETMESSAGE
))
945 //DPRINT1("Peek WH_GETMESSAGE -> %x\n",&Msg);
946 co_HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, RemoveMsg
& PM_REMOVE
, (LPARAM
)&Msg
->Msg
);
955 NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
963 NTUSERGETMESSAGEINFO Info
;
964 PWINDOW_OBJECT Window
;
965 PMSGMEMORY MsgMemoryEntry
;
969 DECLARE_RETURN(BOOL
);
971 DPRINT("Enter NtUserPeekMessage\n");
972 UserEnterExclusive();
974 if (hWnd
== (HWND
)-1 || hWnd
== (HWND
)0x0000FFFF || hWnd
== (HWND
)0xFFFFFFFF)
978 if (hWnd
&& hWnd
!= (HWND
)1)
980 if (!(Window
= UserGetWindowObject(hWnd
)))
987 Window
= (PWINDOW_OBJECT
)hWnd
;
990 if (MsgFilterMax
< MsgFilterMin
)
996 Present
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
);
1001 /* See if this message type is present in the table */
1002 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
1003 if (NULL
== MsgMemoryEntry
)
1005 /* Not present, no copying needed */
1006 Info
.LParamSize
= 0;
1010 /* Determine required size */
1011 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
1013 /* Allocate required amount of user-mode memory */
1014 Info
.LParamSize
= Size
;
1016 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
1017 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
1018 if (! NT_SUCCESS(Status
))
1020 SetLastNtError(Status
);
1023 /* Transfer lParam data to user-mode mem */
1024 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
1025 if (! NT_SUCCESS(Status
))
1027 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
1028 &Info
.LParamSize
, MEM_RELEASE
);
1029 SetLastNtError(Status
);
1032 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
1034 if (RemoveMsg
&& Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
1036 ExFreePool((void *) Msg
.Msg
.lParam
);
1038 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
1039 if (! NT_SUCCESS(Status
))
1041 SetLastNtError(Status
);
1049 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
1054 static BOOL FASTCALL
1055 co_IntWaitMessage(PWINDOW_OBJECT Window
,
1060 PUSER_MESSAGE_QUEUE ThreadQueue
;
1064 pti
= PsGetCurrentThreadWin32Thread();
1065 ThreadQueue
= pti
->MessageQueue
;
1069 if (co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, PM_NOREMOVE
))
1074 /* Nothing found. Wait for new messages. */
1075 Status
= co_MsqWaitForNewMessages(ThreadQueue
, Window
, MsgFilterMin
, MsgFilterMax
);
1077 while ((STATUS_WAIT_0
<= Status
&& Status
<= STATUS_WAIT_63
) || STATUS_TIMEOUT
== Status
);
1079 SetLastNtError(Status
);
1085 NtUserGetMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
1090 * FUNCTION: Get a message from the calling thread's message queue.
1092 * UnsafeMsg - Pointer to the structure which receives the returned message.
1093 * Wnd - Window whose messages are to be retrieved.
1094 * MsgFilterMin - Integer value of the lowest message value to be
1096 * MsgFilterMax - Integer value of the highest message value to be
1101 NTUSERGETMESSAGEINFO Info
;
1103 /* FIXME: if initialization is removed, gcc complains that this may be used before initialization. Please review */
1104 PWINDOW_OBJECT Window
= NULL
;
1105 PMSGMEMORY MsgMemoryEntry
;
1109 DECLARE_RETURN(BOOL
);
1110 // USER_REFERENCE_ENTRY Ref;
1112 DPRINT("Enter NtUserGetMessage\n");
1113 UserEnterExclusive();
1115 /* Validate input */
1116 if (hWnd
&& !(Window
= UserGetWindowObject(hWnd
)))
1121 // if (Window) UserRefObjectCo(Window, &Ref);
1123 if (MsgFilterMax
< MsgFilterMin
)
1131 GotMessage
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
);
1135 /* See if this message type is present in the table */
1136 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
1137 if (NULL
== MsgMemoryEntry
)
1139 /* Not present, no copying needed */
1140 Info
.LParamSize
= 0;
1144 /* Determine required size */
1145 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
1147 /* Allocate required amount of user-mode memory */
1148 Info
.LParamSize
= Size
;
1150 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
1151 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
1153 if (! NT_SUCCESS(Status
))
1155 SetLastNtError(Status
);
1158 /* Transfer lParam data to user-mode mem */
1159 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
1160 if (! NT_SUCCESS(Status
))
1162 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
1163 &Info
.LParamSize
, MEM_DECOMMIT
);
1164 SetLastNtError(Status
);
1167 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
1169 if (Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
1171 ExFreePool((void *) Msg
.Msg
.lParam
);
1173 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
1174 if (! NT_SUCCESS(Status
))
1176 SetLastNtError(Status
);
1180 else if (! co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
))
1185 while (! GotMessage
);
1187 RETURN( WM_QUIT
!= Info
.Msg
.message
);
1190 // if (Window) UserDerefObjectCo(Window);
1192 DPRINT("Leave NtUserGetMessage\n");
1198 static NTSTATUS FASTCALL
1199 CopyMsgToKernelMem(MSG
*KernelModeMsg
, MSG
*UserModeMsg
, PMSGMEMORY MsgMemoryEntry
)
1206 *KernelModeMsg
= *UserModeMsg
;
1208 /* See if this message type is present in the table */
1209 if (NULL
== MsgMemoryEntry
)
1211 /* Not present, no copying needed */
1212 return STATUS_SUCCESS
;
1215 /* Determine required size */
1216 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
1220 /* Allocate kernel mem */
1221 KernelMem
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
1222 if (NULL
== KernelMem
)
1224 DPRINT1("Not enough memory to copy message to kernel mem\n");
1225 return STATUS_NO_MEMORY
;
1227 KernelModeMsg
->lParam
= (LPARAM
) KernelMem
;
1229 /* Copy data if required */
1230 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_READ
))
1232 Status
= MmCopyFromCaller(KernelMem
, (PVOID
) UserModeMsg
->lParam
, Size
);
1233 if (! NT_SUCCESS(Status
))
1235 DPRINT1("Failed to copy message to kernel: invalid usermode buffer\n");
1236 ExFreePoolWithTag(KernelMem
, TAG_MSG
);
1242 /* Make sure we don't pass any secrets to usermode */
1243 RtlZeroMemory(KernelMem
, Size
);
1248 KernelModeMsg
->lParam
= 0;
1251 return STATUS_SUCCESS
;
1254 static NTSTATUS FASTCALL
1255 CopyMsgToUserMem(MSG
*UserModeMsg
, MSG
*KernelModeMsg
)
1258 PMSGMEMORY MsgMemoryEntry
;
1261 /* See if this message type is present in the table */
1262 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
->message
);
1263 if (NULL
== MsgMemoryEntry
)
1265 /* Not present, no copying needed */
1266 return STATUS_SUCCESS
;
1269 /* Determine required size */
1270 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
1274 /* Copy data if required */
1275 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_WRITE
))
1277 Status
= MmCopyToCaller((PVOID
) UserModeMsg
->lParam
, (PVOID
) KernelModeMsg
->lParam
, Size
);
1278 if (! NT_SUCCESS(Status
))
1280 DPRINT1("Failed to copy message from kernel: invalid usermode buffer\n");
1281 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1286 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1289 return STATUS_SUCCESS
;
1293 UserPostThreadMessage( DWORD idThread
,
1300 PTHREADINFO pThread
;
1301 LARGE_INTEGER LargeTickCount
;
1304 DPRINT1("UserPostThreadMessage wParam 0x%x lParam 0x%x\n", wParam
,lParam
);
1306 if (FindMsgMemory(Msg
) != 0)
1308 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1312 Status
= PsLookupThreadByThreadId((HANDLE
)idThread
,&peThread
);
1314 if( Status
== STATUS_SUCCESS
)
1316 pThread
= (PTHREADINFO
)peThread
->Tcb
.Win32Thread
;
1317 if( !pThread
|| !pThread
->MessageQueue
)
1319 ObDereferenceObject( peThread
);
1323 Message
.hwnd
= NULL
;
1324 Message
.message
= Msg
;
1325 Message
.wParam
= wParam
;
1326 Message
.lParam
= lParam
;
1327 IntGetCursorLocation(pThread
->Desktop
->WindowStation
, &Message
.pt
);
1328 KeQueryTickCount(&LargeTickCount
);
1329 pThread
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1330 MsqPostMessage(pThread
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1331 ObDereferenceObject( peThread
);
1336 SetLastNtError( Status
);
1342 UserPostMessage(HWND Wnd
,
1349 LARGE_INTEGER LargeTickCount
;
1351 if (FindMsgMemory(Msg
) != 0)
1353 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1358 return UserPostThreadMessage( PtrToInt(PsGetCurrentThreadId()),
1363 pti
= PsGetCurrentThreadWin32Thread();
1364 if (Wnd
== HWND_BROADCAST
)
1367 PWINDOW_OBJECT DesktopWindow
;
1370 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1371 List
= IntWinListChildren(DesktopWindow
);
1375 for (i
= 0; List
[i
]; i
++)
1376 UserPostMessage(List
[i
], Msg
, wParam
, lParam
);
1382 PWINDOW_OBJECT Window
;
1384 Window
= UserGetWindowObject(Wnd
);
1389 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
1391 DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd
);
1392 /* FIXME - last error code? */
1398 MsqPostQuitMessage(Window
->MessageQueue
, wParam
);
1403 Message
.message
= Msg
;
1404 Message
.wParam
= wParam
;
1405 Message
.lParam
= lParam
;
1406 IntGetCursorLocation(pti
->Desktop
->WindowStation
, &Message
.pt
);
1407 KeQueryTickCount(&LargeTickCount
);
1408 pti
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1409 MsqPostMessage(Window
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1417 NtUserPostMessage(HWND hWnd
,
1422 DECLARE_RETURN(BOOL
);
1424 DPRINT("Enter NtUserPostMessage\n");
1425 UserEnterExclusive();
1427 RETURN( UserPostMessage(hWnd
, Msg
, wParam
, lParam
));
1430 DPRINT("Leave NtUserPostMessage, ret=%i\n",_ret_
);
1438 NtUserPostThreadMessage(DWORD idThread
,
1443 DECLARE_RETURN(BOOL
);
1445 DPRINT("Enter NtUserPostThreadMessage\n");
1446 UserEnterExclusive();
1448 RETURN( UserPostThreadMessage( idThread
,
1454 DPRINT("Leave NtUserPostThreadMessage, ret=%i\n",_ret_
);
1460 NtUserQuerySendMessage(DWORD Unknown0
)
1468 co_IntSendMessage(HWND hWnd
,
1473 ULONG_PTR Result
= 0;
1474 if(co_IntSendMessageTimeout(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
))
1476 return (LRESULT
)Result
;
1483 co_IntSendMessageTimeoutSingle(HWND hWnd
,
1493 PWINDOW_OBJECT Window
= NULL
;
1494 PMSGMEMORY MsgMemoryEntry
;
1495 INT lParamBufferSize
;
1496 LPARAM lParamPacked
;
1497 PTHREADINFO Win32Thread
;
1498 DECLARE_RETURN(LRESULT
);
1499 USER_REFERENCE_ENTRY Ref
;
1501 if (!(Window
= UserGetWindowObject(hWnd
)))
1506 UserRefObjectCo(Window
, &Ref
);
1508 Win32Thread
= PsGetCurrentThreadWin32Thread();
1510 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1512 if (NULL
!= Win32Thread
&&
1513 Window
->MessageQueue
== Win32Thread
->MessageQueue
)
1515 if (Win32Thread
->IsExiting
)
1517 /* Never send messages to exiting threads */
1521 /* See if this message type is present in the table */
1522 MsgMemoryEntry
= FindMsgMemory(Msg
);
1523 if (NULL
== MsgMemoryEntry
)
1525 lParamBufferSize
= -1;
1529 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1532 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
)))
1534 DPRINT1("Failed to pack message parameters\n");
1538 Result
= (ULONG_PTR
)co_IntCallWindowProc(Window
->Wnd
->lpfnWndProc
, !Window
->Wnd
->Unicode
, hWnd
, Msg
, wParam
,
1539 lParamPacked
,lParamBufferSize
);
1546 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1548 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
)))
1550 DPRINT1("Failed to unpack message parameters\n");
1557 if (uFlags
& SMTO_ABORTIFHUNG
&& MsqIsHung(Window
->MessageQueue
))
1559 /* FIXME - Set a LastError? */
1563 if (Window
->Status
& WINDOWSTATUS_DESTROYING
)
1565 /* FIXME - last error? */
1566 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1572 Status
= co_MsqSendMessage( Window
->MessageQueue
,
1578 (uFlags
& SMTO_BLOCK
),
1582 while ((STATUS_TIMEOUT
== Status
) &&
1583 (uFlags
& SMTO_NOTIMEOUTIFNOTHUNG
) &&
1584 !MsqIsHung(Window
->MessageQueue
));
1586 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1588 if (STATUS_TIMEOUT
== Status
)
1592 Microsoft Windows 2000: If GetLastError returns zero, then the function
1594 XP+ : If the function fails or times out, the return value is zero.
1595 To get extended error information, call GetLastError. If GetLastError
1596 returns ERROR_TIMEOUT, then the function timed out.
1598 SetLastWin32Error(ERROR_TIMEOUT
);
1601 else if (! NT_SUCCESS(Status
))
1603 SetLastNtError(Status
);
1610 if (Window
) UserDerefObjectCo(Window
);
1615 co_IntSendMessageTimeout(HWND hWnd
,
1623 PWINDOW_OBJECT DesktopWindow
;
1627 if (HWND_BROADCAST
!= hWnd
)
1629 return co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1632 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1633 if (NULL
== DesktopWindow
)
1635 SetLastWin32Error(ERROR_INTERNAL_ERROR
);
1639 Children
= IntWinListChildren(DesktopWindow
);
1640 if (NULL
== Children
)
1645 for (Child
= Children
; NULL
!= *Child
; Child
++)
1647 co_IntSendMessageTimeoutSingle(*Child
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1650 ExFreePool(Children
);
1652 return (LRESULT
) TRUE
;
1656 /* This function posts a message if the destination's message queue belongs to
1657 another thread, otherwise it sends the message. It does not support broadcast
1660 co_IntPostOrSendMessage(HWND hWnd
,
1667 PWINDOW_OBJECT Window
;
1669 if(hWnd
== HWND_BROADCAST
)
1674 if(!(Window
= UserGetWindowObject(hWnd
)))
1679 pti
= PsGetCurrentThreadWin32Thread();
1680 if(Window
->MessageQueue
!= pti
->MessageQueue
&& FindMsgMemory(Msg
) ==0)
1682 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1686 if(!co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
)) {
1691 return (LRESULT
)Result
;
1695 co_IntDoSendMessage(HWND hWnd
,
1700 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1703 LRESULT Result
= TRUE
;
1705 PWINDOW_OBJECT Window
= NULL
;
1706 NTUSERSENDMESSAGEINFO Info
;
1709 PMSGMEMORY MsgMemoryEntry
;
1711 RtlZeroMemory(&Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1713 /* FIXME: Call hooks. */
1714 if (HWND_BROADCAST
!= hWnd
)
1716 Window
= UserGetWindowObject(hWnd
);
1719 /* Tell usermode to not touch this one */
1720 Info
.HandledByKernel
= TRUE
;
1721 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1728 /* FIXME: Check for an exiting window. */
1730 /* See if the current thread can handle the message */
1731 pti
= PsGetCurrentThreadWin32Thread();
1732 if (HWND_BROADCAST
!= hWnd
&& NULL
!= pti
&&
1733 Window
->MessageQueue
== pti
->MessageQueue
)
1735 /* Gather the information usermode needs to call the window proc directly */
1736 Info
.HandledByKernel
= FALSE
;
1738 Status
= MmCopyFromCaller(&(Info
.Ansi
), &(UnsafeInfo
->Ansi
),
1740 if (! NT_SUCCESS(Status
))
1742 Info
.Ansi
= ! Window
->Wnd
->Unicode
;
1745 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1747 if (Window
->Wnd
->IsSystem
)
1749 Info
.Proc
= (!Info
.Ansi
? Window
->Wnd
->lpfnWndProc
: Window
->Wnd
->WndProcExtra
);
1753 Info
.Ansi
= !Window
->Wnd
->Unicode
;
1754 Info
.Proc
= Window
->Wnd
->lpfnWndProc
;
1757 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, &Result
);
1762 /* Must be handled by other thread */
1763 // if (HWND_BROADCAST != hWnd)
1765 // UserDereferenceObject(Window);
1767 Info
.HandledByKernel
= TRUE
;
1768 UserModeMsg
.hwnd
= hWnd
;
1769 UserModeMsg
.message
= Msg
;
1770 UserModeMsg
.wParam
= wParam
;
1771 UserModeMsg
.lParam
= lParam
;
1772 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1773 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1774 if (! NT_SUCCESS(Status
))
1776 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1777 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1778 return (dsm
? 0 : -1);
1782 Result
= co_IntSendMessage(KernelModeMsg
.hwnd
, KernelModeMsg
.message
,
1783 KernelModeMsg
.wParam
, KernelModeMsg
.lParam
);
1787 Result
= co_IntSendMessageTimeout(KernelModeMsg
.hwnd
, KernelModeMsg
.message
,
1788 KernelModeMsg
.wParam
, KernelModeMsg
.lParam
,
1789 dsm
->uFlags
, dsm
->uTimeout
, &dsm
->Result
);
1791 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1792 if (! NT_SUCCESS(Status
))
1794 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1795 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1796 return(dsm
? 0 : -1);
1800 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1801 if (! NT_SUCCESS(Status
))
1803 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1806 return (LRESULT
)Result
;
1810 NtUserSendMessageTimeout(HWND hWnd
,
1817 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1821 DECLARE_RETURN(BOOL
);
1823 DPRINT("Enter NtUserSendMessageTimeout\n");
1824 UserEnterExclusive();
1826 dsm
.uFlags
= uFlags
;
1827 dsm
.uTimeout
= uTimeout
;
1828 Result
= co_IntDoSendMessage(hWnd
, Msg
, wParam
, lParam
, &dsm
, UnsafeInfo
);
1829 if(uResult
!= NULL
&& Result
!= 0)
1833 Status
= MmCopyToCaller(uResult
, &dsm
.Result
, sizeof(ULONG_PTR
));
1834 if(!NT_SUCCESS(Status
))
1836 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1843 DPRINT("Leave NtUserSendMessageTimeout, ret=%i\n",_ret_
);
1849 NtUserSendMessage(HWND Wnd
,
1853 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1855 DECLARE_RETURN(BOOL
);
1857 DPRINT("Enter NtUserSendMessage\n");
1858 UserEnterExclusive();
1860 RETURN(co_IntDoSendMessage(Wnd
, Msg
, wParam
, lParam
, NULL
, UnsafeInfo
));
1863 DPRINT("Leave NtUserSendMessage, ret=%i\n",_ret_
);
1870 UserSendNotifyMessage(HWND hWnd
,
1877 if (FindMsgMemory(Msg
) != 0)
1879 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1883 // Basicly the same as IntPostOrSendMessage
1884 if (hWnd
== HWND_BROADCAST
) //Handle Broadcast
1887 PWINDOW_OBJECT DesktopWindow
;
1890 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1891 List
= IntWinListChildren(DesktopWindow
);
1895 for (i
= 0; List
[i
]; i
++)
1897 UserSendNotifyMessage(List
[i
], Msg
, wParam
, lParam
);
1906 PWINDOW_OBJECT Window
;
1909 if(!(Window
= UserGetWindowObject(hWnd
))) return FALSE
;
1911 pti
= PsGetCurrentThreadWin32Thread();
1912 if(Window
->MessageQueue
!= pti
->MessageQueue
)
1913 { // Send message w/o waiting for it.
1914 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1917 { // Handle message and callback.
1918 Message
.hwnd
= hWnd
;
1919 Message
.message
= Msg
;
1920 Message
.wParam
= wParam
;
1921 Message
.lParam
= lParam
;
1923 Result
= co_IntSendMessageTimeoutSingle( hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &PResult
);
1931 NtUserWaitMessage(VOID
)
1933 DECLARE_RETURN(BOOL
);
1935 DPRINT("EnterNtUserWaitMessage\n");
1936 UserEnterExclusive();
1938 RETURN(co_IntWaitMessage(NULL
, 0, 0));
1941 DPRINT("Leave NtUserWaitMessage, ret=%i\n",_ret_
);
1947 IntGetQueueStatus(BOOL ClearChanges
)
1950 PUSER_MESSAGE_QUEUE Queue
;
1952 DECLARE_RETURN(DWORD
);
1954 DPRINT("Enter IntGetQueueStatus\n");
1956 pti
= PsGetCurrentThreadWin32Thread();
1957 Queue
= pti
->MessageQueue
;
1959 Result
= MAKELONG(Queue
->QueueBits
, Queue
->ChangedBits
);
1962 Queue
->ChangedBits
= 0;
1968 DPRINT("Leave IntGetQueueStatus, ret=%i\n",_ret_
);
1973 IntInitMessagePumpHook()
1975 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1977 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
++;
1984 IntUninitMessagePumpHook()
1986 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1988 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
<= 0)
1992 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
--;
2005 ULONG_PTR ResultInfo
,
2006 DWORD dwType
, // fnID?
2009 LRESULT lResult
= 0;
2011 BOOL BadChk
= FALSE
;
2012 PWINDOW_OBJECT Window
= NULL
;
2013 USER_REFERENCE_ENTRY Ref
;
2015 UserEnterExclusive();
2017 /* Validate input */
2018 if (hWnd
&& (hWnd
!= INVALID_HANDLE_VALUE
) && !(Window
= UserGetWindowObject(hWnd
)))
2025 case FNID_DEFWINDOWPROC
:
2026 UserRefObjectCo(Window
, &Ref
);
2027 lResult
= IntDefWindowProc(Window
, Msg
, wParam
, lParam
, Ansi
);
2029 UserDerefObjectCo(Window
);
2031 case FNID_SENDNOTIFYMESSAGE
:
2032 Ret
= UserSendNotifyMessage(hWnd
, Msg
, wParam
, lParam
);
2034 case FNID_BROADCASTSYSTEMMESSAGE
:
2037 DWORD_PTR RetVal
= 0;
2043 ProbeForWrite((PVOID
)ResultInfo
,
2044 sizeof(BROADCASTPARM
),
2046 RtlCopyMemory(&parm
, (PVOID
)ResultInfo
, sizeof(BROADCASTPARM
));
2048 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2058 if ( parm
.recipients
& BSM_ALLDESKTOPS
||
2059 parm
.recipients
== BSM_ALLCOMPONENTS
)
2062 else if (parm
.recipients
& BSM_APPLICATIONS
)
2064 if (parm
.flags
& BSF_QUERY
)
2066 if (parm
.flags
& BSF_FORCEIFHUNG
|| parm
.flags
& BSF_NOHANG
)
2068 co_IntSendMessageTimeout( HWND_BROADCAST
,
2076 else if (parm
.flags
& BSF_NOTIMEOUTIFNOTHUNG
)
2078 co_IntSendMessageTimeout( HWND_BROADCAST
,
2082 SMTO_NOTIMEOUTIFNOTHUNG
,
2088 co_IntSendMessageTimeout( HWND_BROADCAST
,
2097 else if (parm
.flags
& BSF_POSTMESSAGE
)
2099 Ret
= UserPostMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2101 else if ( parm
.flags
& BSF_SENDNOTIFYMESSAGE
)
2103 Ret
= UserSendNotifyMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2108 case FNID_SENDMESSAGECALLBACK
:
2110 // CallNextHook bypass.
2111 case FNID_CALLWNDPROC
:
2112 case FNID_CALLWNDPROCRET
:
2114 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
2115 PHOOK NextObj
, Hook
= ClientInfo
->phkCurrent
;
2117 if (!ClientInfo
|| !Hook
) break;
2119 UserReferenceObject(Hook
);
2121 if (Hook
->Thread
&& (Hook
->Thread
!= PsGetCurrentThread()))
2123 UserDereferenceObject(Hook
);
2127 NextObj
= IntGetNextHook(Hook
);
2128 ClientInfo
->phkCurrent
= NextObj
;
2130 if ( Hook
->HookId
== WH_CALLWNDPROC
)
2135 CWP
.wParam
= wParam
;
2136 CWP
.lParam
= lParam
;
2137 DPRINT("WH_CALLWNDPROC: Hook %x NextHook %x\n", Hook
, NextObj
);
2139 lResult
= co_IntCallHookProc( Hook
->HookId
,
2141 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2152 CWPR
.wParam
= wParam
;
2153 CWPR
.lParam
= lParam
;
2154 CWPR
.lResult
= ClientInfo
->dwHookData
;
2156 lResult
= co_IntCallHookProc( Hook
->HookId
,
2158 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2164 UserDereferenceObject(Hook
);
2165 lResult
= (LRESULT
) NextObj
;
2172 case FNID_DEFWINDOWPROC
:
2173 case FNID_CALLWNDPROC
:
2174 case FNID_CALLWNDPROCRET
:
2179 ProbeForWrite((PVOID
)ResultInfo
, sizeof(LRESULT
), 1);
2180 RtlCopyMemory((PVOID
)ResultInfo
, &lResult
, sizeof(LRESULT
));
2182 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2195 return BadChk
? FALSE
: Ret
;
2198 #define INFINITE 0xFFFFFFFF
2199 #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
2203 NtUserWaitForInputIdle(
2205 IN DWORD dwMilliseconds
,
2209 PPROCESSINFO W32Process
;
2212 LARGE_INTEGER Timeout
;
2213 ULONGLONG StartTime
, Run
, Elapsed
= 0;
2215 UserEnterExclusive();
2217 Status
= ObReferenceObjectByHandle(hProcess
,
2218 PROCESS_QUERY_INFORMATION
,
2224 if (!NT_SUCCESS(Status
))
2227 SetLastNtError(Status
);
2231 W32Process
= (PPROCESSINFO
)Process
->Win32Process
;
2234 ObDereferenceObject(Process
);
2236 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2240 EngCreateEvent((PEVENT
*)&W32Process
->InputIdleEvent
);
2242 Handles
[0] = Process
;
2243 Handles
[1] = W32Process
->InputIdleEvent
;
2247 ObDereferenceObject(Process
);
2249 return STATUS_SUCCESS
; /* no event to wait on */
2252 StartTime
= EngGetTickCount();
2254 Run
= dwMilliseconds
;
2256 DPRINT("WFII: waiting for %p\n", Handles
[1] );
2259 Timeout
.QuadPart
= Run
- Elapsed
;
2261 Status
= KeWaitForMultipleObjects( 2,
2267 dwMilliseconds
== INFINITE
? NULL
: &Timeout
,
2269 UserEnterExclusive();
2271 if (!NT_SUCCESS(Status
))
2273 SetLastNtError(Status
);
2274 Status
= WAIT_FAILED
;
2281 Status
= WAIT_FAILED
;
2287 co_IntPeekMessage( &Msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2291 case STATUS_USER_APC
:
2292 case STATUS_ALERTED
:
2293 case STATUS_TIMEOUT
:
2294 DPRINT1("WFII: timeout\n");
2295 Status
= STATUS_TIMEOUT
;
2299 DPRINT1("WFII: finished\n");
2300 Status
= STATUS_SUCCESS
;
2304 if (dwMilliseconds
!= INFINITE
)
2306 Elapsed
= EngGetTickCount() - StartTime
;
2309 Status
= STATUS_TIMEOUT
;
2316 if (W32Process
->InputIdleEvent
)
2318 EngDeleteEvent((PEVENT
)W32Process
->InputIdleEvent
);
2319 W32Process
->InputIdleEvent
= NULL
;
2321 ObDereferenceObject(Process
);