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
->ti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
297 if ((!SameThread
&& (Window
->ti
->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
->ti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
320 if ((!SameThread
&& (Window
->ti
->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(PUSER_MESSAGE_QUEUE ThreadQueue
, LPMSG Msg
, PWINDOW_OBJECT MsgWindow
,
491 PWINDOW_OBJECT Parent
;
493 ASSERT_REFS_CO(MsgWindow
);
495 if(*HitTest
== (USHORT
)HTTRANSPARENT
)
497 /* eat the message, search again! */
501 Parent
= IntGetParent(MsgWindow
);//fixme: deref retval?
503 /* If no parent window, pass MsgWindows HWND as wParam. Fixes bug #3111 */
504 Result
= co_IntSendMessage(MsgWindow
->hSelf
,
506 (WPARAM
) (Parent
? Parent
->hSelf
: MsgWindow
->hSelf
),
507 (LPARAM
)MAKELONG(*HitTest
, Msg
->message
)
512 case MA_NOACTIVATEANDEAT
:
516 case MA_ACTIVATEANDEAT
:
517 co_IntMouseActivateWindow(MsgWindow
);
521 co_IntMouseActivateWindow(MsgWindow
);
529 co_IntTranslateMouseMessage(PUSER_MESSAGE_QUEUE ThreadQueue
, LPMSG Msg
, USHORT
*HitTest
, BOOL Remove
)
531 PWINDOW_OBJECT Window
;
532 USER_REFERENCE_ENTRY Ref
, DesktopRef
;
534 if(!(Window
= UserGetWindowObject(Msg
->hwnd
)))
536 /* let's just eat the message?! */
540 UserRefObjectCo(Window
, &Ref
);
542 if(ThreadQueue
== Window
->MessageQueue
&&
543 ThreadQueue
->CaptureWindow
!= Window
->hSelf
)
545 /* only send WM_NCHITTEST messages if we're not capturing the window! */
546 *HitTest
= co_IntSendMessage(Window
->hSelf
, WM_NCHITTEST
, 0,
547 MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
));
549 if(*HitTest
== (USHORT
)HTTRANSPARENT
)
551 PWINDOW_OBJECT DesktopWindow
;
552 HWND hDesktop
= IntGetDesktopWindow();
554 if((DesktopWindow
= UserGetWindowObject(hDesktop
)))
558 UserRefObjectCo(DesktopWindow
, &DesktopRef
);
560 co_WinPosWindowFromPoint(DesktopWindow
, Window
->MessageQueue
, &Msg
->pt
, &Wnd
);
565 /* post the message to the other window */
566 Msg
->hwnd
= Wnd
->hSelf
;
567 if(!(Wnd
->Status
& WINDOWSTATUS_DESTROYING
))
569 MsqPostMessage(Wnd
->MessageQueue
, Msg
, FALSE
,
570 Msg
->message
== WM_MOUSEMOVE
? QS_MOUSEMOVE
:
574 /* eat the message */
575 UserDereferenceObject(Wnd
);
576 UserDerefObjectCo(DesktopWindow
);
577 UserDerefObjectCo(Window
);
580 UserDereferenceObject(Wnd
);
583 UserDerefObjectCo(DesktopWindow
);
592 if (gspv
.bMouseClickLock
&& ((Msg
->message
== WM_LBUTTONUP
) || (Msg
->message
== WM_LBUTTONDOWN
)))
594 if (MsqIsClkLck(Msg
, Remove
))
596 // FIXME: drop the message, hack: use WM_NULL
597 Msg
->message
= WM_NULL
;
601 if(IS_BTN_MESSAGE(Msg
->message
, DOWN
))
603 /* generate double click messages, if necessary */
604 if ((((*HitTest
) != HTCLIENT
) ||
605 (Window
->Wnd
->pcls
->style
& CS_DBLCLKS
)) &&
606 MsqIsDblClk(Msg
, Remove
))
608 Msg
->message
+= WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
;
612 if(Msg
->message
!= WM_MOUSEWHEEL
)
615 if ((*HitTest
) != HTCLIENT
)
617 Msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
618 if((Msg
->message
== WM_NCRBUTTONUP
) &&
619 (((*HitTest
) == HTCAPTION
) || ((*HitTest
) == HTSYSMENU
)))
621 Msg
->message
= WM_CONTEXTMENU
;
622 Msg
->wParam
= (WPARAM
)Window
->hSelf
;
626 Msg
->wParam
= *HitTest
;
628 Msg
->lParam
= MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
);
630 else if(ThreadQueue
->MoveSize
== NULL
&&
631 ThreadQueue
->MenuOwner
== NULL
)
633 /* NOTE: Msg->pt should remain in screen coordinates. -- FiN */
634 Msg
->lParam
= MAKELONG(
635 Msg
->pt
.x
- (WORD
)Window
->Wnd
->rcClient
.left
,
636 Msg
->pt
.y
- (WORD
)Window
->Wnd
->rcClient
.top
);
640 UserDerefObjectCo(Window
);
645 * Internal version of PeekMessage() doing all the work
648 co_IntPeekMessage(PUSER_MESSAGE Msg
,
649 PWINDOW_OBJECT Window
,
655 LARGE_INTEGER LargeTickCount
;
656 PUSER_MESSAGE_QUEUE ThreadQueue
;
657 PUSER_MESSAGE Message
;
658 BOOL Present
, RemoveMessages
;
659 USER_REFERENCE_ENTRY Ref
;
661 MOUSEHOOKSTRUCT MHook
;
663 /* The queues and order in which they are checked are documented in the MSDN
664 article on GetMessage() */
666 pti
= PsGetCurrentThreadWin32Thread();
667 ThreadQueue
= pti
->MessageQueue
;
669 /* Inspect RemoveMsg flags */
670 /* FIXME: The only flag we process is PM_REMOVE - processing of others must still be implemented */
671 RemoveMessages
= RemoveMsg
& PM_REMOVE
;
677 KeQueryTickCount(&LargeTickCount
);
678 ThreadQueue
->LastMsgRead
= LargeTickCount
.u
.LowPart
;
680 /* Dispatch sent messages here. */
681 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
684 /* Now look for a quit message. */
686 if (ThreadQueue
->QuitPosted
)
688 /* According to the PSDK, WM_QUIT messages are always returned, regardless
689 of the filter specified */
690 Msg
->Msg
.hwnd
= NULL
;
691 Msg
->Msg
.message
= WM_QUIT
;
692 Msg
->Msg
.wParam
= ThreadQueue
->QuitExitCode
;
694 Msg
->FreeLParam
= FALSE
;
697 ThreadQueue
->QuitPosted
= FALSE
;
702 /* Now check for normal messages. */
703 Present
= co_MsqFindMessage(ThreadQueue
,
712 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
715 MsqDestroyMessage(Message
);
720 /* Check for hardware events. */
721 Present
= co_MsqFindMessage(ThreadQueue
,
730 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
733 MsqDestroyMessage(Message
);
738 /* Check for sent messages again. */
739 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
742 /* Check for paint messages. */
743 if (IntGetPaintMessage(Window
, MsgFilterMin
, MsgFilterMax
, pti
, &Msg
->Msg
, RemoveMessages
))
745 Msg
->FreeLParam
= FALSE
;
749 if (ThreadQueue
->WakeMask
& QS_TIMER
)
750 if (PostTimerMessages(Window
)) // If there are timers ready,
751 goto CheckMessages
; // go back and process them.
753 // LOL! Polling Timer Queue? How much time is spent doing this?
754 /* Check for WM_(SYS)TIMER messages */
755 Present
= MsqGetTimerMessage(ThreadQueue
, Window
, MsgFilterMin
, MsgFilterMax
,
756 &Msg
->Msg
, RemoveMessages
);
759 Msg
->FreeLParam
= FALSE
;
769 PWINDOW_OBJECT MsgWindow
= NULL
;
771 if(Msg
->Msg
.hwnd
&& (MsgWindow
= UserGetWindowObject(Msg
->Msg
.hwnd
)) &&
772 Msg
->Msg
.message
>= WM_MOUSEFIRST
&& Msg
->Msg
.message
<= WM_MOUSELAST
)
776 UserRefObjectCo(MsgWindow
, &Ref
);
778 if(co_IntTranslateMouseMessage(ThreadQueue
, &Msg
->Msg
, &HitTest
, TRUE
))
779 /* FIXME - check message filter again, if the message doesn't match anymore,
782 UserDerefObjectCo(MsgWindow
);
783 /* eat the message, search again */
787 if(ThreadQueue
->CaptureWindow
== NULL
)
789 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
790 if((Msg
->Msg
.message
!= WM_MOUSEMOVE
&& Msg
->Msg
.message
!= WM_NCMOUSEMOVE
) &&
791 IS_BTN_MESSAGE(Msg
->Msg
.message
, DOWN
) &&
792 co_IntActivateWindowMouse(ThreadQueue
, &Msg
->Msg
, MsgWindow
, &HitTest
))
794 UserDerefObjectCo(MsgWindow
);
795 /* eat the message, search again */
800 UserDerefObjectCo(MsgWindow
);
804 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
809 // UserDereferenceObject(MsgWindow);
815 if((Msg
->Msg
.hwnd
&& Msg
->Msg
.message
>= WM_MOUSEFIRST
&& Msg
->Msg
.message
<= WM_MOUSELAST
) &&
816 co_IntTranslateMouseMessage(ThreadQueue
, &Msg
->Msg
, &HitTest
, FALSE
))
817 /* FIXME - check message filter again, if the message doesn't match anymore,
820 /* eat the message, search again */
824 if ( ISITHOOKED(WH_MOUSE
) &&
825 Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
826 Msg
->Msg
.message
<= WM_MOUSELAST
)
828 MHook
.pt
= Msg
->Msg
.pt
;
829 MHook
.hwnd
= Msg
->Msg
.hwnd
;
830 MHook
.wHitTestCode
= HitTest
;
831 MHook
.dwExtraInfo
= 0;
832 if (co_HOOK_CallHooks( WH_MOUSE
,
833 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
837 if (ISITHOOKED(WH_CBT
))
839 MHook
.pt
= Msg
->Msg
.pt
;
840 MHook
.hwnd
= Msg
->Msg
.hwnd
;
841 MHook
.wHitTestCode
= HitTest
;
842 MHook
.dwExtraInfo
= 0;
843 co_HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
,
844 Msg
->Msg
.message
, (LPARAM
)&MHook
);
849 if ( ISITHOOKED(WH_KEYBOARD
) &&
850 (Msg
->Msg
.message
== WM_KEYDOWN
|| Msg
->Msg
.message
== WM_KEYUP
) )
852 if (co_HOOK_CallHooks( WH_KEYBOARD
,
853 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
854 LOWORD(Msg
->Msg
.wParam
),
857 if (ISITHOOKED(WH_CBT
))
859 /* skip this message */
860 co_HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
,
861 LOWORD(Msg
->Msg
.wParam
), Msg
->Msg
.lParam
);
866 // The WH_GETMESSAGE hook enables an application to monitor messages about to
867 // be returned by the GetMessage or PeekMessage function.
868 if (ISITHOOKED(WH_GETMESSAGE
))
870 //DPRINT1("Peek WH_GETMESSAGE -> %x\n",&Msg);
871 co_HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, RemoveMsg
& PM_REMOVE
, (LPARAM
)&Msg
->Msg
);
880 co_IntGetPeekMessage( PMSG pMsg
,
892 co_IntWaitMessage(PWINDOW_OBJECT Window
,
897 PUSER_MESSAGE_QUEUE ThreadQueue
;
901 pti
= PsGetCurrentThreadWin32Thread();
902 ThreadQueue
= pti
->MessageQueue
;
906 if (co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, PM_NOREMOVE
))
910 /* Nothing found. Wait for new messages. */
911 Status
= co_MsqWaitForNewMessages(ThreadQueue
, Window
, MsgFilterMin
, MsgFilterMax
);
913 while ((STATUS_WAIT_0
<= Status
&& Status
<= STATUS_WAIT_63
) || STATUS_TIMEOUT
== Status
);
915 SetLastNtError(Status
);
921 static NTSTATUS FASTCALL
922 CopyMsgToKernelMem(MSG
*KernelModeMsg
, MSG
*UserModeMsg
, PMSGMEMORY MsgMemoryEntry
)
929 *KernelModeMsg
= *UserModeMsg
;
931 /* See if this message type is present in the table */
932 if (NULL
== MsgMemoryEntry
)
934 /* Not present, no copying needed */
935 return STATUS_SUCCESS
;
938 /* Determine required size */
939 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
943 /* Allocate kernel mem */
944 KernelMem
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
945 if (NULL
== KernelMem
)
947 DPRINT1("Not enough memory to copy message to kernel mem\n");
948 return STATUS_NO_MEMORY
;
950 KernelModeMsg
->lParam
= (LPARAM
) KernelMem
;
952 /* Copy data if required */
953 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_READ
))
955 Status
= MmCopyFromCaller(KernelMem
, (PVOID
) UserModeMsg
->lParam
, Size
);
956 if (! NT_SUCCESS(Status
))
958 DPRINT1("Failed to copy message to kernel: invalid usermode buffer\n");
959 ExFreePoolWithTag(KernelMem
, TAG_MSG
);
965 /* Make sure we don't pass any secrets to usermode */
966 RtlZeroMemory(KernelMem
, Size
);
971 KernelModeMsg
->lParam
= 0;
974 return STATUS_SUCCESS
;
977 static NTSTATUS FASTCALL
978 CopyMsgToUserMem(MSG
*UserModeMsg
, MSG
*KernelModeMsg
)
981 PMSGMEMORY MsgMemoryEntry
;
984 /* See if this message type is present in the table */
985 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
->message
);
986 if (NULL
== MsgMemoryEntry
)
988 /* Not present, no copying needed */
989 return STATUS_SUCCESS
;
992 /* Determine required size */
993 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
997 /* Copy data if required */
998 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_WRITE
))
1000 Status
= MmCopyToCaller((PVOID
) UserModeMsg
->lParam
, (PVOID
) KernelModeMsg
->lParam
, Size
);
1001 if (! NT_SUCCESS(Status
))
1003 DPRINT1("Failed to copy message from kernel: invalid usermode buffer\n");
1004 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1009 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1012 return STATUS_SUCCESS
;
1016 UserPostThreadMessage( DWORD idThread
,
1023 PTHREADINFO pThread
;
1024 LARGE_INTEGER LargeTickCount
;
1027 DPRINT1("UserPostThreadMessage wParam 0x%x lParam 0x%x\n", wParam
,lParam
);
1029 if (FindMsgMemory(Msg
) != 0)
1031 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1035 Status
= PsLookupThreadByThreadId((HANDLE
)idThread
,&peThread
);
1037 if( Status
== STATUS_SUCCESS
)
1039 pThread
= (PTHREADINFO
)peThread
->Tcb
.Win32Thread
;
1040 if( !pThread
|| !pThread
->MessageQueue
|| (pThread
->TIF_flags
& TIF_INCLEANUP
))
1042 ObDereferenceObject( peThread
);
1046 Message
.hwnd
= NULL
;
1047 Message
.message
= Msg
;
1048 Message
.wParam
= wParam
;
1049 Message
.lParam
= lParam
;
1050 IntGetCursorLocation(pThread
->Desktop
->WindowStation
, &Message
.pt
);
1051 KeQueryTickCount(&LargeTickCount
);
1052 pThread
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1053 MsqPostMessage(pThread
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1054 ObDereferenceObject( peThread
);
1059 SetLastNtError( Status
);
1065 UserPostMessage(HWND Wnd
,
1072 LARGE_INTEGER LargeTickCount
;
1074 if (FindMsgMemory(Msg
) != 0)
1076 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1081 return UserPostThreadMessage( PtrToInt(PsGetCurrentThreadId()),
1086 if (Wnd
== HWND_BROADCAST
)
1089 PWINDOW_OBJECT DesktopWindow
;
1092 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1093 List
= IntWinListChildren(DesktopWindow
);
1097 for (i
= 0; List
[i
]; i
++)
1098 UserPostMessage(List
[i
], Msg
, wParam
, lParam
);
1104 PWINDOW_OBJECT Window
;
1106 Window
= UserGetWindowObject(Wnd
);
1107 if ( !Window
|| !Window
->Wnd
)
1112 pti
= Window
->Wnd
->head
.pti
;
1113 if ( pti
->TIF_flags
& TIF_INCLEANUP
)
1115 DPRINT1("Attempted to post message to window 0x%x when the thread is in cleanup!\n", Wnd
);
1119 if ( Window
->Status
& WINDOWSTATUS_DESTROYING
)
1121 DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd
);
1122 /* FIXME - last error code? */
1128 MsqPostQuitMessage(Window
->MessageQueue
, wParam
);
1133 Message
.message
= Msg
;
1134 Message
.wParam
= wParam
;
1135 Message
.lParam
= lParam
;
1136 IntGetCursorLocation(pti
->Desktop
->WindowStation
, &Message
.pt
);
1137 KeQueryTickCount(&LargeTickCount
);
1138 pti
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1139 MsqPostMessage(Window
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1147 co_IntSendMessage(HWND hWnd
,
1152 ULONG_PTR Result
= 0;
1153 if(co_IntSendMessageTimeout(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
))
1155 return (LRESULT
)Result
;
1162 co_IntSendMessageTimeoutSingle(HWND hWnd
,
1172 PWINDOW_OBJECT Window
= NULL
;
1173 PMSGMEMORY MsgMemoryEntry
;
1174 INT lParamBufferSize
;
1175 LPARAM lParamPacked
;
1176 PTHREADINFO Win32Thread
;
1177 DECLARE_RETURN(LRESULT
);
1178 USER_REFERENCE_ENTRY Ref
;
1180 if (!(Window
= UserGetWindowObject(hWnd
)))
1185 UserRefObjectCo(Window
, &Ref
);
1187 Win32Thread
= PsGetCurrentThreadWin32Thread();
1189 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1191 if (NULL
!= Win32Thread
&&
1192 Window
->MessageQueue
== Win32Thread
->MessageQueue
)
1194 if (Win32Thread
->TIF_flags
& TIF_INCLEANUP
)
1196 /* Never send messages to exiting threads */
1200 /* See if this message type is present in the table */
1201 MsgMemoryEntry
= FindMsgMemory(Msg
);
1202 if (NULL
== MsgMemoryEntry
)
1204 lParamBufferSize
= -1;
1208 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1211 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
)))
1213 DPRINT1("Failed to pack message parameters\n");
1217 Result
= (ULONG_PTR
)co_IntCallWindowProc( Window
->Wnd
->lpfnWndProc
,
1218 !Window
->Wnd
->Unicode
,
1229 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1231 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
)))
1233 DPRINT1("Failed to unpack message parameters\n");
1240 if (uFlags
& SMTO_ABORTIFHUNG
&& MsqIsHung(Window
->MessageQueue
))
1242 /* FIXME - Set a LastError? */
1246 if (Window
->Status
& WINDOWSTATUS_DESTROYING
)
1248 /* FIXME - last error? */
1249 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1255 Status
= co_MsqSendMessage( Window
->MessageQueue
,
1261 (uFlags
& SMTO_BLOCK
),
1265 while ((STATUS_TIMEOUT
== Status
) &&
1266 (uFlags
& SMTO_NOTIMEOUTIFNOTHUNG
) &&
1267 !MsqIsHung(Window
->MessageQueue
));
1269 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1271 if (STATUS_TIMEOUT
== Status
)
1275 Microsoft Windows 2000: If GetLastError returns zero, then the function
1277 XP+ : If the function fails or times out, the return value is zero.
1278 To get extended error information, call GetLastError. If GetLastError
1279 returns ERROR_TIMEOUT, then the function timed out.
1281 SetLastWin32Error(ERROR_TIMEOUT
);
1284 else if (! NT_SUCCESS(Status
))
1286 SetLastNtError(Status
);
1293 if (Window
) UserDerefObjectCo(Window
);
1298 co_IntSendMessageTimeout(HWND hWnd
,
1306 PWINDOW_OBJECT DesktopWindow
;
1310 if (HWND_BROADCAST
!= hWnd
)
1312 return co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1315 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1316 if (NULL
== DesktopWindow
)
1318 SetLastWin32Error(ERROR_INTERNAL_ERROR
);
1322 Children
= IntWinListChildren(DesktopWindow
);
1323 if (NULL
== Children
)
1328 for (Child
= Children
; NULL
!= *Child
; Child
++)
1330 co_IntSendMessageTimeoutSingle(*Child
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1333 ExFreePool(Children
);
1335 return (LRESULT
) TRUE
;
1339 /* This function posts a message if the destination's message queue belongs to
1340 another thread, otherwise it sends the message. It does not support broadcast
1343 co_IntPostOrSendMessage(HWND hWnd
,
1350 PWINDOW_OBJECT Window
;
1352 if(hWnd
== HWND_BROADCAST
)
1357 if(!(Window
= UserGetWindowObject(hWnd
)))
1362 pti
= PsGetCurrentThreadWin32Thread();
1363 if(Window
->MessageQueue
!= pti
->MessageQueue
&& FindMsgMemory(Msg
) ==0)
1365 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1369 if(!co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
)) {
1374 return (LRESULT
)Result
;
1378 co_IntDoSendMessage(HWND hWnd
,
1383 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1386 LRESULT Result
= TRUE
;
1388 PWINDOW_OBJECT Window
= NULL
;
1389 NTUSERSENDMESSAGEINFO Info
;
1392 PMSGMEMORY MsgMemoryEntry
;
1394 RtlZeroMemory(&Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1396 /* FIXME: Call hooks. */
1397 if (HWND_BROADCAST
!= hWnd
)
1399 Window
= UserGetWindowObject(hWnd
);
1402 /* Tell usermode to not touch this one */
1403 Info
.HandledByKernel
= TRUE
;
1404 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1411 /* FIXME: Check for an exiting window. */
1413 /* See if the current thread can handle the message */
1414 pti
= PsGetCurrentThreadWin32Thread();
1415 if (HWND_BROADCAST
!= hWnd
&& NULL
!= pti
&&
1416 Window
->MessageQueue
== pti
->MessageQueue
)
1418 /* Gather the information usermode needs to call the window proc directly */
1419 Info
.HandledByKernel
= FALSE
;
1421 Status
= MmCopyFromCaller(&(Info
.Ansi
), &(UnsafeInfo
->Ansi
),
1423 if (! NT_SUCCESS(Status
))
1425 Info
.Ansi
= ! Window
->Wnd
->Unicode
;
1428 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1430 Info
.Ansi
= !Window
->Wnd
->Unicode
;
1431 Info
.Proc
= Window
->Wnd
->lpfnWndProc
;
1433 // Make the call from here if CALLWNDPROC or CALLWNDPROCRET are hooked
1434 // or just do it in User32!
1436 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, &Result
);
1440 /* Must be handled by other thread */
1441 // if (HWND_BROADCAST != hWnd)
1443 // UserDereferenceObject(Window);
1445 Info
.HandledByKernel
= TRUE
;
1446 UserModeMsg
.hwnd
= hWnd
;
1447 UserModeMsg
.message
= Msg
;
1448 UserModeMsg
.wParam
= wParam
;
1449 UserModeMsg
.lParam
= lParam
;
1450 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1451 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1452 if (! NT_SUCCESS(Status
))
1454 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1455 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1456 return (dsm
? 0 : -1);
1460 Result
= co_IntSendMessage(KernelModeMsg
.hwnd
, KernelModeMsg
.message
,
1461 KernelModeMsg
.wParam
, KernelModeMsg
.lParam
);
1465 Result
= co_IntSendMessageTimeout(KernelModeMsg
.hwnd
, KernelModeMsg
.message
,
1466 KernelModeMsg
.wParam
, KernelModeMsg
.lParam
,
1467 dsm
->uFlags
, dsm
->uTimeout
, &dsm
->Result
);
1469 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1470 if (! NT_SUCCESS(Status
))
1472 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1473 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1474 return(dsm
? 0 : -1);
1478 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1479 if (! NT_SUCCESS(Status
))
1481 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1484 return (LRESULT
)Result
;
1489 UserSendNotifyMessage(HWND hWnd
,
1496 if (FindMsgMemory(Msg
) != 0)
1498 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1502 // Basicly the same as IntPostOrSendMessage
1503 if (hWnd
== HWND_BROADCAST
) //Handle Broadcast
1506 PWINDOW_OBJECT DesktopWindow
;
1509 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1510 List
= IntWinListChildren(DesktopWindow
);
1514 for (i
= 0; List
[i
]; i
++)
1516 UserSendNotifyMessage(List
[i
], Msg
, wParam
, lParam
);
1525 PWINDOW_OBJECT Window
;
1528 if(!(Window
= UserGetWindowObject(hWnd
))) return FALSE
;
1530 pti
= PsGetCurrentThreadWin32Thread();
1531 if(Window
->MessageQueue
!= pti
->MessageQueue
)
1532 { // Send message w/o waiting for it.
1533 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1536 { // Handle message and callback.
1537 Message
.hwnd
= hWnd
;
1538 Message
.message
= Msg
;
1539 Message
.wParam
= wParam
;
1540 Message
.lParam
= lParam
;
1542 Result
= co_IntSendMessageTimeoutSingle( hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &PResult
);
1550 IntGetQueueStatus(BOOL ClearChanges
)
1553 PUSER_MESSAGE_QUEUE Queue
;
1555 DECLARE_RETURN(DWORD
);
1557 DPRINT("Enter IntGetQueueStatus\n");
1559 pti
= PsGetCurrentThreadWin32Thread();
1560 Queue
= pti
->MessageQueue
;
1562 Result
= MAKELONG(Queue
->QueueBits
, Queue
->ChangedBits
);
1565 Queue
->ChangedBits
= 0;
1571 DPRINT("Leave IntGetQueueStatus, ret=%i\n",_ret_
);
1576 IntInitMessagePumpHook()
1578 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1580 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
++;
1587 IntUninitMessagePumpHook()
1589 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1591 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
<= 0)
1595 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
--;
1601 /** Functions ******************************************************************/
1604 NtUserPostMessage(HWND hWnd
,
1609 DECLARE_RETURN(BOOL
);
1611 DPRINT("Enter NtUserPostMessage\n");
1612 UserEnterExclusive();
1614 RETURN( UserPostMessage(hWnd
, Msg
, wParam
, lParam
));
1617 DPRINT("Leave NtUserPostMessage, ret=%i\n",_ret_
);
1623 NtUserPostThreadMessage(DWORD idThread
,
1628 DECLARE_RETURN(BOOL
);
1630 DPRINT("Enter NtUserPostThreadMessage\n");
1631 UserEnterExclusive();
1633 RETURN( UserPostThreadMessage( idThread
,
1639 DPRINT("Leave NtUserPostThreadMessage, ret=%i\n",_ret_
);
1645 NtUserQuerySendMessage(DWORD Unknown0
)
1653 NtUserSendMessageTimeout(HWND hWnd
,
1660 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1664 DECLARE_RETURN(BOOL
);
1666 DPRINT("Enter NtUserSendMessageTimeout\n");
1667 UserEnterExclusive();
1669 dsm
.uFlags
= uFlags
;
1670 dsm
.uTimeout
= uTimeout
;
1671 Result
= co_IntDoSendMessage(hWnd
, Msg
, wParam
, lParam
, &dsm
, UnsafeInfo
);
1672 if(uResult
!= NULL
&& Result
!= 0)
1676 Status
= MmCopyToCaller(uResult
, &dsm
.Result
, sizeof(ULONG_PTR
));
1677 if(!NT_SUCCESS(Status
))
1679 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1686 DPRINT("Leave NtUserSendMessageTimeout, ret=%i\n",_ret_
);
1692 NtUserSendMessage(HWND Wnd
,
1696 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1698 DECLARE_RETURN(BOOL
);
1700 DPRINT("Enter NtUserSendMessage\n");
1701 UserEnterExclusive();
1703 RETURN(co_IntDoSendMessage(Wnd
, Msg
, wParam
, lParam
, NULL
, UnsafeInfo
));
1706 DPRINT("Leave NtUserSendMessage, ret=%i\n",_ret_
);
1712 NtUserWaitMessage(VOID
)
1714 DECLARE_RETURN(BOOL
);
1716 DPRINT("EnterNtUserWaitMessage\n");
1717 UserEnterExclusive();
1719 RETURN(co_IntWaitMessage(NULL
, 0, 0));
1722 DPRINT("Leave NtUserWaitMessage, ret=%i\n",_ret_
);
1729 NtUserGetMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
1734 * FUNCTION: Get a message from the calling thread's message queue.
1736 * UnsafeMsg - Pointer to the structure which receives the returned message.
1737 * Wnd - Window whose messages are to be retrieved.
1738 * MsgFilterMin - Integer value of the lowest message value to be
1740 * MsgFilterMax - Integer value of the highest message value to be
1745 NTUSERGETMESSAGEINFO Info
;
1747 /* FIXME: if initialization is removed, gcc complains that this may be used before initialization. Please review */
1748 PWINDOW_OBJECT Window
= NULL
;
1749 PMSGMEMORY MsgMemoryEntry
;
1753 DECLARE_RETURN(BOOL
);
1754 // USER_REFERENCE_ENTRY Ref;
1756 DPRINT("Enter NtUserGetMessage\n");
1757 UserEnterExclusive();
1759 /* Validate input */
1760 if (hWnd
&& !(Window
= UserGetWindowObject(hWnd
)))
1765 // if (Window) UserRefObjectCo(Window, &Ref);
1767 if (MsgFilterMax
< MsgFilterMin
)
1775 GotMessage
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
);
1779 /* See if this message type is present in the table */
1780 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
1781 if (NULL
== MsgMemoryEntry
)
1783 /* Not present, no copying needed */
1784 Info
.LParamSize
= 0;
1788 /* Determine required size */
1789 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
1791 /* Allocate required amount of user-mode memory */
1792 Info
.LParamSize
= Size
;
1794 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
1795 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
1797 if (! NT_SUCCESS(Status
))
1799 SetLastNtError(Status
);
1802 /* Transfer lParam data to user-mode mem */
1803 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
1804 if (! NT_SUCCESS(Status
))
1806 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
1807 &Info
.LParamSize
, MEM_DECOMMIT
);
1808 SetLastNtError(Status
);
1811 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
1813 if (Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
1815 ExFreePool((void *) Msg
.Msg
.lParam
);
1817 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
1818 if (! NT_SUCCESS(Status
))
1820 SetLastNtError(Status
);
1824 else if (! co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
))
1829 while (! GotMessage
);
1831 RETURN( WM_QUIT
!= Info
.Msg
.message
);
1834 // if (Window) UserDerefObjectCo(Window);
1836 DPRINT("Leave NtUserGetMessage\n");
1852 DECLARE_RETURN(BOOL
);
1854 DPRINT("Enter NtUserGetMessage\n");
1855 UserEnterExclusive();
1857 if ( (MsgFilterMin
|MsgFilterMax
) & ~WM_MAXIMUM
)
1859 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1863 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
, TRUE
);
1869 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
1870 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
1872 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1874 SetLastNtError(_SEH2_GetExceptionCode());
1882 DPRINT("Leave NtUserGetMessage\n");
1888 NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
1896 NTUSERGETMESSAGEINFO Info
;
1897 PWINDOW_OBJECT Window
;
1898 PMSGMEMORY MsgMemoryEntry
;
1902 DECLARE_RETURN(BOOL
);
1904 DPRINT("Enter NtUserPeekMessage\n");
1905 UserEnterExclusive();
1907 if (hWnd
== (HWND
)-1 || hWnd
== (HWND
)0x0000FFFF || hWnd
== (HWND
)0xFFFFFFFF)
1910 /* Validate input */
1911 if (hWnd
&& hWnd
!= (HWND
)1)
1913 if (!(Window
= UserGetWindowObject(hWnd
)))
1920 Window
= (PWINDOW_OBJECT
)hWnd
;
1923 if (MsgFilterMax
< MsgFilterMin
)
1929 Present
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
);
1934 /* See if this message type is present in the table */
1935 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
1936 if (NULL
== MsgMemoryEntry
)
1938 /* Not present, no copying needed */
1939 Info
.LParamSize
= 0;
1943 /* Determine required size */
1944 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
1946 /* Allocate required amount of user-mode memory */
1947 Info
.LParamSize
= Size
;
1949 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
1950 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
1951 if (! NT_SUCCESS(Status
))
1953 SetLastNtError(Status
);
1956 /* Transfer lParam data to user-mode mem */
1957 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
1958 if (! NT_SUCCESS(Status
))
1960 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
1961 &Info
.LParamSize
, MEM_RELEASE
);
1962 SetLastNtError(Status
);
1965 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
1967 if (RemoveMsg
&& Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
1969 ExFreePool((void *) Msg
.Msg
.lParam
);
1971 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
1972 if (! NT_SUCCESS(Status
))
1974 SetLastNtError(Status
);
1982 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
1998 DECLARE_RETURN(BOOL
);
2000 DPRINT("Enter NtUserPeekMessage\n");
2001 UserEnterExclusive();
2003 if ( RemoveMsg
& PM_BADMSGFLAGS
)
2005 SetLastWin32Error(ERROR_INVALID_FLAGS
);
2009 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
, FALSE
);
2015 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
2016 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
2018 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2020 SetLastNtError(_SEH2_GetExceptionCode());
2028 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2035 NtUserCallMsgFilter(
2039 BOOL BadChk
= FALSE
, Ret
= FALSE
;
2041 DECLARE_RETURN(BOOL
);
2043 DPRINT("Enter NtUserCallMsgFilter\n");
2044 UserEnterExclusive();
2049 ProbeForRead((PVOID
)lpmsg
,
2052 RtlCopyMemory( &Msg
,
2056 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2065 if (BadChk
) RETURN( FALSE
);
2067 if ( ISITHOOKED(WH_SYSMSGFILTER
) &&
2068 co_HOOK_CallHooks( WH_SYSMSGFILTER
, code
, 0, (LPARAM
)&Msg
))
2074 if ( ISITHOOKED(WH_MSGFILTER
) )
2076 Ret
= co_HOOK_CallHooks( WH_MSGFILTER
, code
, 0, (LPARAM
)&Msg
);
2082 ProbeForWrite((PVOID
)lpmsg
,
2085 RtlCopyMemory((PVOID
)lpmsg
,
2089 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2094 if (BadChk
) RETURN( FALSE
);
2098 DPRINT("Leave NtUserCallMsgFilter. ret=%i\n", _ret_
);
2104 NtUserDispatchMessage(PMSG UnsafeMsgInfo
)
2110 UserEnterExclusive();
2113 ProbeForRead(UnsafeMsgInfo
, sizeof(MSG
), 1);
2114 RtlCopyMemory(&SafeMsg
, UnsafeMsgInfo
, sizeof(MSG
));
2116 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2118 SetLastNtError(_SEH2_GetExceptionCode());
2123 if (!Hit
) Res
= IntDispatchMessage(&SafeMsg
);
2131 NtUserTranslateMessage(LPMSG lpMsg
,
2136 DECLARE_RETURN(BOOL
);
2138 DPRINT("Enter NtUserTranslateMessage\n");
2139 UserEnterExclusive();
2141 Status
= MmCopyFromCaller(&SafeMsg
, lpMsg
, sizeof(MSG
));
2142 if(!NT_SUCCESS(Status
))
2144 SetLastNtError(Status
);
2148 RETURN( IntTranslateKbdMessage(&SafeMsg
, dwhkl
));
2151 DPRINT("Leave NtUserTranslateMessage: ret=%i\n",_ret_
);
2162 ULONG_PTR ResultInfo
,
2163 DWORD dwType
, // fnID?
2166 LRESULT lResult
= 0;
2168 BOOL BadChk
= FALSE
;
2169 PWINDOW_OBJECT Window
= NULL
;
2170 USER_REFERENCE_ENTRY Ref
;
2172 UserEnterExclusive();
2174 /* Validate input */
2175 if (hWnd
&& (hWnd
!= INVALID_HANDLE_VALUE
) && !(Window
= UserGetWindowObject(hWnd
)))
2182 case FNID_DEFWINDOWPROC
:
2183 UserRefObjectCo(Window
, &Ref
);
2184 lResult
= IntDefWindowProc(Window
, Msg
, wParam
, lParam
, Ansi
);
2186 UserDerefObjectCo(Window
);
2188 case FNID_SENDNOTIFYMESSAGE
:
2189 Ret
= UserSendNotifyMessage(hWnd
, Msg
, wParam
, lParam
);
2191 case FNID_BROADCASTSYSTEMMESSAGE
:
2194 DWORD_PTR RetVal
= 0;
2200 ProbeForWrite((PVOID
)ResultInfo
,
2201 sizeof(BROADCASTPARM
),
2203 RtlCopyMemory(&parm
, (PVOID
)ResultInfo
, sizeof(BROADCASTPARM
));
2205 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2215 if ( parm
.recipients
& BSM_ALLDESKTOPS
||
2216 parm
.recipients
== BSM_ALLCOMPONENTS
)
2219 else if (parm
.recipients
& BSM_APPLICATIONS
)
2221 if (parm
.flags
& BSF_QUERY
)
2223 if (parm
.flags
& BSF_FORCEIFHUNG
|| parm
.flags
& BSF_NOHANG
)
2225 co_IntSendMessageTimeout( HWND_BROADCAST
,
2233 else if (parm
.flags
& BSF_NOTIMEOUTIFNOTHUNG
)
2235 co_IntSendMessageTimeout( HWND_BROADCAST
,
2239 SMTO_NOTIMEOUTIFNOTHUNG
,
2245 co_IntSendMessageTimeout( HWND_BROADCAST
,
2254 else if (parm
.flags
& BSF_POSTMESSAGE
)
2256 Ret
= UserPostMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2258 else if ( parm
.flags
& BSF_SENDNOTIFYMESSAGE
)
2260 Ret
= UserSendNotifyMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2265 case FNID_SENDMESSAGECALLBACK
:
2267 // CallNextHook bypass.
2268 case FNID_CALLWNDPROC
:
2269 case FNID_CALLWNDPROCRET
:
2271 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
2272 PHOOK NextObj
, Hook
= ClientInfo
->phkCurrent
;
2274 if (!ClientInfo
|| !Hook
) break;
2276 UserReferenceObject(Hook
);
2278 if (Hook
->Thread
&& (Hook
->Thread
!= PsGetCurrentThread()))
2280 UserDereferenceObject(Hook
);
2284 NextObj
= IntGetNextHook(Hook
);
2285 ClientInfo
->phkCurrent
= NextObj
;
2287 if ( Hook
->HookId
== WH_CALLWNDPROC
)
2292 CWP
.wParam
= wParam
;
2293 CWP
.lParam
= lParam
;
2294 DPRINT("WH_CALLWNDPROC: Hook %x NextHook %x\n", Hook
, NextObj
);
2296 lResult
= co_IntCallHookProc( Hook
->HookId
,
2298 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2309 CWPR
.wParam
= wParam
;
2310 CWPR
.lParam
= lParam
;
2311 CWPR
.lResult
= ClientInfo
->dwHookData
;
2313 lResult
= co_IntCallHookProc( Hook
->HookId
,
2315 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2321 UserDereferenceObject(Hook
);
2322 lResult
= (LRESULT
) NextObj
;
2329 case FNID_DEFWINDOWPROC
:
2330 case FNID_CALLWNDPROC
:
2331 case FNID_CALLWNDPROCRET
:
2336 ProbeForWrite((PVOID
)ResultInfo
, sizeof(LRESULT
), 1);
2337 RtlCopyMemory((PVOID
)ResultInfo
, &lResult
, sizeof(LRESULT
));
2339 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2352 return BadChk
? FALSE
: Ret
;
2355 #define INFINITE 0xFFFFFFFF
2356 #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
2360 NtUserWaitForInputIdle(
2362 IN DWORD dwMilliseconds
,
2366 PPROCESSINFO W32Process
;
2369 LARGE_INTEGER Timeout
;
2370 ULONGLONG StartTime
, Run
, Elapsed
= 0;
2372 UserEnterExclusive();
2374 Status
= ObReferenceObjectByHandle(hProcess
,
2375 PROCESS_QUERY_INFORMATION
,
2381 if (!NT_SUCCESS(Status
))
2384 SetLastNtError(Status
);
2388 W32Process
= (PPROCESSINFO
)Process
->Win32Process
;
2391 ObDereferenceObject(Process
);
2393 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2397 EngCreateEvent((PEVENT
*)&W32Process
->InputIdleEvent
);
2399 Handles
[0] = Process
;
2400 Handles
[1] = W32Process
->InputIdleEvent
;
2404 ObDereferenceObject(Process
);
2406 return STATUS_SUCCESS
; /* no event to wait on */
2409 StartTime
= EngGetTickCount();
2411 Run
= dwMilliseconds
;
2413 DPRINT("WFII: waiting for %p\n", Handles
[1] );
2416 Timeout
.QuadPart
= Run
- Elapsed
;
2418 Status
= KeWaitForMultipleObjects( 2,
2424 dwMilliseconds
== INFINITE
? NULL
: &Timeout
,
2426 UserEnterExclusive();
2428 if (!NT_SUCCESS(Status
))
2430 SetLastNtError(Status
);
2431 Status
= WAIT_FAILED
;
2438 Status
= WAIT_FAILED
;
2444 co_IntPeekMessage( &Msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2448 case STATUS_USER_APC
:
2449 case STATUS_ALERTED
:
2450 case STATUS_TIMEOUT
:
2451 DPRINT1("WFII: timeout\n");
2452 Status
= STATUS_TIMEOUT
;
2456 DPRINT1("WFII: finished\n");
2457 Status
= STATUS_SUCCESS
;
2461 if (dwMilliseconds
!= INFINITE
)
2463 Elapsed
= EngGetTickCount() - StartTime
;
2466 Status
= STATUS_TIMEOUT
;
2473 if (W32Process
->InputIdleEvent
)
2475 EngDeleteEvent((PEVENT
)W32Process
->InputIdleEvent
);
2476 W32Process
->InputIdleEvent
= NULL
;
2478 ObDereferenceObject(Process
);