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
, BOOL NonPagedPoolNeeded
)
170 NCCALCSIZE_PARAMS
*UnpackedNcCalcsize
;
171 NCCALCSIZE_PARAMS
*PackedNcCalcsize
;
172 CREATESTRUCTW
*UnpackedCs
;
173 CREATESTRUCTW
*PackedCs
;
174 PLARGE_STRING WindowName
;
175 PUNICODE_STRING ClassName
;
180 *lParamPacked
= lParam
;
182 if (NonPagedPoolNeeded
)
183 PoolType
= NonPagedPool
;
185 PoolType
= PagedPool
;
187 if (WM_NCCALCSIZE
== Msg
&& wParam
)
190 UnpackedNcCalcsize
= (NCCALCSIZE_PARAMS
*) lParam
;
191 PackedNcCalcsize
= ExAllocatePoolWithTag(PoolType
,
192 sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
),
195 if (NULL
== PackedNcCalcsize
)
197 DPRINT1("Not enough memory to pack lParam\n");
198 return STATUS_NO_MEMORY
;
200 RtlCopyMemory(PackedNcCalcsize
, UnpackedNcCalcsize
, sizeof(NCCALCSIZE_PARAMS
));
201 PackedNcCalcsize
->lppos
= (PWINDOWPOS
) (PackedNcCalcsize
+ 1);
202 RtlCopyMemory(PackedNcCalcsize
->lppos
, UnpackedNcCalcsize
->lppos
, sizeof(WINDOWPOS
));
203 *lParamPacked
= (LPARAM
) PackedNcCalcsize
;
205 else if (WM_CREATE
== Msg
|| WM_NCCREATE
== Msg
)
207 UnpackedCs
= (CREATESTRUCTW
*) lParam
;
208 WindowName
= (PLARGE_STRING
) UnpackedCs
->lpszName
;
209 ClassName
= (PUNICODE_STRING
) UnpackedCs
->lpszClass
;
210 Size
= sizeof(CREATESTRUCTW
) + WindowName
->Length
+ sizeof(WCHAR
);
211 if (IS_ATOM(ClassName
->Buffer
))
213 Size
+= sizeof(WCHAR
) + sizeof(ATOM
);
217 Size
+= sizeof(WCHAR
) + ClassName
->Length
+ sizeof(WCHAR
);
219 PackedCs
= ExAllocatePoolWithTag(PoolType
, Size
, TAG_MSG
);
220 if (NULL
== PackedCs
)
222 DPRINT1("Not enough memory to pack lParam\n");
223 return STATUS_NO_MEMORY
;
225 RtlCopyMemory(PackedCs
, UnpackedCs
, sizeof(CREATESTRUCTW
));
226 CsData
= (PCHAR
) (PackedCs
+ 1);
227 PackedCs
->lpszName
= (LPCWSTR
) (CsData
- (PCHAR
) PackedCs
);
228 RtlCopyMemory(CsData
, WindowName
->Buffer
, WindowName
->Length
);
229 CsData
+= WindowName
->Length
;
230 *((WCHAR
*) CsData
) = L
'\0';
231 CsData
+= sizeof(WCHAR
);
232 PackedCs
->lpszClass
= (LPCWSTR
) (CsData
- (PCHAR
) PackedCs
);
233 if (IS_ATOM(ClassName
->Buffer
))
235 *((WCHAR
*) CsData
) = L
'A';
236 CsData
+= sizeof(WCHAR
);
237 *((ATOM
*) CsData
) = (ATOM
)(DWORD_PTR
) ClassName
->Buffer
;
238 CsData
+= sizeof(ATOM
);
242 *((WCHAR
*) CsData
) = L
'S';
243 CsData
+= sizeof(WCHAR
);
244 RtlCopyMemory(CsData
, ClassName
->Buffer
, ClassName
->Length
);
245 CsData
+= ClassName
->Length
;
246 *((WCHAR
*) CsData
) = L
'\0';
247 CsData
+= sizeof(WCHAR
);
249 ASSERT(CsData
== (PCHAR
) PackedCs
+ Size
);
250 *lParamPacked
= (LPARAM
) PackedCs
;
253 else if (PoolType
== NonPagedPool
)
255 PMSGMEMORY MsgMemoryEntry
;
258 MsgMemoryEntry
= FindMsgMemory(Msg
);
260 if ((!MsgMemoryEntry
) || (MsgMemoryEntry
->Size
< 0))
262 /* Keep previous behavior */
263 return STATUS_SUCCESS
;
265 PackedData
= ExAllocatePoolWithTag(NonPagedPool
, MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
), TAG_MSG
);
266 RtlCopyMemory(PackedData
, (PVOID
)lParam
, MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
));
267 *lParamPacked
= (LPARAM
)PackedData
;
270 return STATUS_SUCCESS
;
274 UnpackParam(LPARAM lParamPacked
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, BOOL NonPagedPoolUsed
)
276 NCCALCSIZE_PARAMS
*UnpackedParams
;
277 NCCALCSIZE_PARAMS
*PackedParams
;
278 PWINDOWPOS UnpackedWindowPos
;
280 if (lParamPacked
== lParam
)
282 return STATUS_SUCCESS
;
285 if (WM_NCCALCSIZE
== Msg
&& wParam
)
287 PackedParams
= (NCCALCSIZE_PARAMS
*) lParamPacked
;
288 UnpackedParams
= (NCCALCSIZE_PARAMS
*) lParam
;
289 UnpackedWindowPos
= UnpackedParams
->lppos
;
290 RtlCopyMemory(UnpackedParams
, PackedParams
, sizeof(NCCALCSIZE_PARAMS
));
291 UnpackedParams
->lppos
= UnpackedWindowPos
;
292 RtlCopyMemory(UnpackedWindowPos
, PackedParams
+ 1, sizeof(WINDOWPOS
));
293 ExFreePool((PVOID
) lParamPacked
);
295 return STATUS_SUCCESS
;
297 else if (WM_CREATE
== Msg
|| WM_NCCREATE
== Msg
)
299 ExFreePool((PVOID
) lParamPacked
);
301 return STATUS_SUCCESS
;
303 else if (NonPagedPoolUsed
)
305 PMSGMEMORY MsgMemoryEntry
;
306 MsgMemoryEntry
= FindMsgMemory(Msg
);
307 if (MsgMemoryEntry
->Size
< 0)
309 /* Keep previous behavior */
310 return STATUS_INVALID_PARAMETER
;
313 if (MsgMemory
->Flags
== MMS_FLAG_READWRITE
)
315 //RtlCopyMemory((PVOID)lParam, (PVOID)lParamPacked, MsgMemory->Size);
317 ExFreePool((PVOID
) lParamPacked
);
318 return STATUS_SUCCESS
;
323 return STATUS_INVALID_PARAMETER
;
330 ( PWINDOW_OBJECT Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
332 BOOL SameThread
= FALSE
;
334 if (Window
->pti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
337 if ((!SameThread
&& (Window
->pti
->fsHooks
& HOOKID_TO_FLAG(WH_CALLWNDPROC
))) ||
338 (SameThread
&& ISITHOOKED(WH_CALLWNDPROC
)) )
345 co_HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, SameThread
, (LPARAM
)&CWP
);
353 ( PWINDOW_OBJECT Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*uResult
)
355 BOOL SameThread
= FALSE
;
357 if (Window
->pti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
360 if ((!SameThread
&& (Window
->pti
->fsHooks
& HOOKID_TO_FLAG(WH_CALLWNDPROCRET
))) ||
361 (SameThread
&& ISITHOOKED(WH_CALLWNDPROCRET
)) )
366 CWPR
.wParam
= wParam
;
367 CWPR
.lParam
= lParam
;
368 CWPR
.lResult
= *uResult
;
369 co_HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, SameThread
, (LPARAM
)&CWPR
);
375 IntDispatchMessage(PMSG pMsg
)
377 LARGE_INTEGER TickCount
;
380 PMSGMEMORY MsgMemoryEntry
;
381 INT lParamBufferSize
;
383 PWINDOW_OBJECT Window
= NULL
;
387 Window
= UserGetWindowObject(pMsg
->hwnd
);
388 if (!Window
|| !Window
->Wnd
) return 0;
391 if (((pMsg
->message
== WM_SYSTIMER
) ||
392 (pMsg
->message
== WM_TIMER
)) &&
395 if (pMsg
->message
== WM_TIMER
)
397 if (ValidateTimerCallback(PsGetCurrentThreadWin32Thread(),Window
,pMsg
->wParam
,pMsg
->lParam
))
399 KeQueryTickCount(&TickCount
);
400 Time
= MsqCalculateMessageTime(&TickCount
);
401 return co_IntCallWindowProc((WNDPROC
)pMsg
->lParam
,
413 PTIMER pTimer
= FindSystemTimer(pMsg
);
414 if (pTimer
&& pTimer
->pfn
)
416 KeQueryTickCount(&TickCount
);
417 Time
= MsqCalculateMessageTime(&TickCount
);
418 pTimer
->pfn(pMsg
->hwnd
, WM_SYSTIMER
, (UINT
)pMsg
->wParam
, Time
);
424 if ( !Window
|| !Window
->Wnd
) return 0;
426 /* See if this message type is present in the table */
427 MsgMemoryEntry
= FindMsgMemory(pMsg
->message
);
428 if ( !MsgMemoryEntry
)
430 lParamBufferSize
= -1;
434 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, pMsg
->wParam
, pMsg
->lParam
);
437 if (! NT_SUCCESS(PackParam(&lParamPacked
, pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
, FALSE
)))
439 DPRINT1("Failed to pack message parameters\n");
443 retval
= co_IntCallWindowProc( Window
->Wnd
->lpfnWndProc
,
444 !Window
->Wnd
->Unicode
,
451 if (! NT_SUCCESS(UnpackParam(lParamPacked
, pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
, FALSE
)))
453 DPRINT1("Failed to unpack message parameters\n");
456 if (pMsg
->message
== WM_PAINT
)
458 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
459 HRGN hrgn
= IntSysCreateRectRgn( 0, 0, 0, 0 );
460 co_UserGetUpdateRgn( Window
, hrgn
, TRUE
);
461 REGION_FreeRgnByHandle( hrgn
);
467 co_IntSendHitTestMessages(PUSER_MESSAGE_QUEUE ThreadQueue
, LPMSG Msg
)
469 if(!Msg
->hwnd
|| ThreadQueue
->CaptureWindow
)
478 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
483 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
490 case WM_LBUTTONDBLCLK
:
491 case WM_MBUTTONDBLCLK
:
492 case WM_RBUTTONDBLCLK
:
493 case WM_XBUTTONDBLCLK
:
496 PSYSTEM_CURSORINFO CurInfo
;
497 CurInfo
= IntGetSysCursorInfo();
499 wParam
= (WPARAM
)(CurInfo
->ButtonsDown
);
501 co_IntSendMessage(Msg
->hwnd
, WM_MOUSEMOVE
, wParam
, Msg
->lParam
);
502 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
505 case WM_NCLBUTTONDOWN
:
506 case WM_NCMBUTTONDOWN
:
507 case WM_NCRBUTTONDOWN
:
508 case WM_NCXBUTTONDOWN
:
509 case WM_NCLBUTTONDBLCLK
:
510 case WM_NCMBUTTONDBLCLK
:
511 case WM_NCRBUTTONDBLCLK
:
512 case WM_NCXBUTTONDBLCLK
:
514 co_IntSendMessage(Msg
->hwnd
, WM_NCMOUSEMOVE
, (WPARAM
)Msg
->wParam
, Msg
->lParam
);
515 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
522 co_IntActivateWindowMouse(
523 PUSER_MESSAGE_QUEUE ThreadQueue
,
525 PWINDOW_OBJECT MsgWindow
,
529 PWINDOW_OBJECT Parent
;
531 ASSERT_REFS_CO(MsgWindow
);
533 if(*HitTest
== (USHORT
)HTTRANSPARENT
)
535 /* eat the message, search again! */
539 Parent
= IntGetParent(MsgWindow
);//fixme: deref retval?
541 /* If no parent window, pass MsgWindows HWND as wParam. Fixes bug #3111 */
542 Result
= co_IntSendMessage(MsgWindow
->hSelf
,
544 (WPARAM
) (Parent
? Parent
->hSelf
: MsgWindow
->hSelf
),
545 (LPARAM
)MAKELONG(*HitTest
, Msg
->message
)
550 case MA_NOACTIVATEANDEAT
:
554 case MA_ACTIVATEANDEAT
:
555 co_IntMouseActivateWindow(MsgWindow
);
559 co_IntMouseActivateWindow(MsgWindow
);
567 co_IntTranslateMouseMessage(
568 PUSER_MESSAGE_QUEUE ThreadQueue
,
573 PWINDOW_OBJECT Window
;
574 USER_REFERENCE_ENTRY Ref
, DesktopRef
;
576 if(!(Window
= UserGetWindowObject(Msg
->hwnd
)))
578 /* let's just eat the message?! */
582 UserRefObjectCo(Window
, &Ref
);
584 if ( ThreadQueue
== Window
->pti
->MessageQueue
&&
585 ThreadQueue
->CaptureWindow
!= Window
->hSelf
)
587 /* only send WM_NCHITTEST messages if we're not capturing the window! */
588 *HitTest
= co_IntSendMessage(Window
->hSelf
, WM_NCHITTEST
, 0,
589 MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
));
591 if (*HitTest
== (USHORT
)HTTRANSPARENT
)
593 PWINDOW_OBJECT DesktopWindow
;
594 HWND hDesktop
= IntGetDesktopWindow();
596 if ((DesktopWindow
= UserGetWindowObject(hDesktop
)))
600 UserRefObjectCo(DesktopWindow
, &DesktopRef
);
602 co_WinPosWindowFromPoint(DesktopWindow
, Window
->pti
->MessageQueue
, &Msg
->pt
, &Wnd
);
607 /* post the message to the other window */
608 Msg
->hwnd
= Wnd
->hSelf
;
609 if(!(Wnd
->state
& WINDOWSTATUS_DESTROYING
))
611 MsqPostMessage(Wnd
->pti
->MessageQueue
, Msg
, FALSE
,
612 Msg
->message
== WM_MOUSEMOVE
? QS_MOUSEMOVE
:
616 /* eat the message */
617 UserDereferenceObject(Wnd
);
618 UserDerefObjectCo(DesktopWindow
);
619 UserDerefObjectCo(Window
);
622 UserDereferenceObject(Wnd
);
625 UserDerefObjectCo(DesktopWindow
);
634 if ( gspv
.bMouseClickLock
&&
635 ( (Msg
->message
== WM_LBUTTONUP
) ||
636 (Msg
->message
== WM_LBUTTONDOWN
) ) )
638 if (MsqIsClkLck(Msg
, Remove
))
640 // FIXME: drop the message, hack: use WM_NULL
641 Msg
->message
= WM_NULL
;
645 if (IS_BTN_MESSAGE(Msg
->message
, DOWN
))
647 /* generate double click messages, if necessary */
648 if ((((*HitTest
) != HTCLIENT
) ||
649 (Window
->Wnd
->pcls
->style
& CS_DBLCLKS
)) &&
650 MsqIsDblClk(Msg
, Remove
))
652 Msg
->message
+= WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
;
656 if(Msg
->message
!= WM_MOUSEWHEEL
)
659 if ((*HitTest
) != HTCLIENT
)
661 Msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
662 if ( (Msg
->message
== WM_NCRBUTTONUP
) &&
663 (((*HitTest
) == HTCAPTION
) || ((*HitTest
) == HTSYSMENU
)) )
665 Msg
->message
= WM_CONTEXTMENU
;
666 Msg
->wParam
= (WPARAM
)Window
->hSelf
;
670 Msg
->wParam
= *HitTest
;
672 Msg
->lParam
= MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
);
674 else if ( ThreadQueue
->MoveSize
== NULL
&&
675 ThreadQueue
->MenuOwner
== NULL
)
677 /* NOTE: Msg->pt should remain in screen coordinates. -- FiN */
678 Msg
->lParam
= MAKELONG(
679 Msg
->pt
.x
- (WORD
)Window
->Wnd
->rcClient
.left
,
680 Msg
->pt
.y
- (WORD
)Window
->Wnd
->rcClient
.top
);
684 UserDerefObjectCo(Window
);
688 BOOL
ProcessMouseMessage(MSG
* Msg
, USHORT HitTest
, UINT RemoveMsg
)
690 MOUSEHOOKSTRUCT MHook
;
693 Event
.message
= Msg
->message
;
694 Event
.time
= Msg
->time
;
695 Event
.hwnd
= Msg
->hwnd
;
696 Event
.paramL
= Msg
->pt
.x
;
697 Event
.paramH
= Msg
->pt
.y
;
698 co_HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&Event
);
702 MHook
.hwnd
= Msg
->hwnd
;
703 MHook
.wHitTestCode
= HitTest
;
704 MHook
.dwExtraInfo
= 0;
705 if (co_HOOK_CallHooks( WH_MOUSE
,
706 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
710 if (ISITHOOKED(WH_CBT
))
713 MHook
.hwnd
= Msg
->hwnd
;
714 MHook
.wHitTestCode
= HitTest
;
715 MHook
.dwExtraInfo
= 0;
716 co_HOOK_CallHooks( WH_CBT
,
727 BOOL
ProcessKeyboardMessage(MSG
* Msg
, UINT RemoveMsg
)
731 Event
.message
= Msg
->message
;
732 Event
.hwnd
= Msg
->hwnd
;
733 Event
.time
= Msg
->time
;
734 Event
.paramL
= (Msg
->wParam
& 0xFF) | (HIWORD(Msg
->lParam
) << 8);
735 Event
.paramH
= Msg
->lParam
& 0x7FFF;
736 if (HIWORD(Msg
->lParam
) & 0x0100) Event
.paramH
|= 0x8000;
737 co_HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&Event
);
739 if (co_HOOK_CallHooks( WH_KEYBOARD
,
740 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
744 if (ISITHOOKED(WH_CBT
))
746 /* skip this message */
747 co_HOOK_CallHooks( WH_CBT
,
757 * Internal version of PeekMessage() doing all the work
760 co_IntPeekMessage( PUSER_MESSAGE Msg
,
761 PWINDOW_OBJECT Window
,
767 LARGE_INTEGER LargeTickCount
;
768 PUSER_MESSAGE_QUEUE ThreadQueue
;
769 PUSER_MESSAGE Message
;
770 BOOL Present
, RemoveMessages
;
771 USER_REFERENCE_ENTRY Ref
;
774 /* The queues and order in which they are checked are documented in the MSDN
775 article on GetMessage() */
777 pti
= PsGetCurrentThreadWin32Thread();
778 ThreadQueue
= pti
->MessageQueue
;
780 /* Inspect RemoveMsg flags */
782 The only flag we process is PM_REMOVE.
783 Processing (High word) PM_QS_Xx Is needed. This and MsgFilterXxx can result
784 with QS_Xx flags to be used to isolate which message check to test for.
785 ATM, we look at all messages and the filters are sent to co_MsqFindMessage
786 and there, it is cross checked.
787 Example: Wine server/queue.c is_keyboard_msg, check_msg_filter and
788 filter_contains_hw_range.
790 RemoveMessages
= RemoveMsg
& PM_REMOVE
;
793 If no filter is specified, messages are processed in the following order:
797 * Input (hardware) messages and system internal events
798 * Sent messages (again)
806 KeQueryTickCount(&LargeTickCount
);
807 ThreadQueue
->LastMsgRead
= LargeTickCount
.u
.LowPart
;
809 /* Dispatch sent messages here. */
810 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
813 /* Now look for a quit message. */
815 if (ThreadQueue
->QuitPosted
)
817 /* According to the PSDK, WM_QUIT messages are always returned, regardless
818 of the filter specified */
819 Msg
->Msg
.hwnd
= NULL
;
820 Msg
->Msg
.message
= WM_QUIT
;
821 Msg
->Msg
.wParam
= ThreadQueue
->QuitExitCode
;
823 Msg
->FreeLParam
= FALSE
;
826 ThreadQueue
->QuitPosted
= FALSE
;
831 /* Now check for normal messages. */
832 Present
= co_MsqFindMessage( ThreadQueue
,
841 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
844 MsqDestroyMessage(Message
);
849 /* Check for hardware events. */
850 Present
= co_MsqFindMessage( ThreadQueue
,
859 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
862 MsqDestroyMessage(Message
);
867 /* Check for sent messages again. */
868 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
871 /* Check for paint messages. */
872 if ( IntGetPaintMessage( Window
,
879 Msg
->FreeLParam
= FALSE
;
883 if (PostTimerMessages(Window
))
892 PWINDOW_OBJECT MsgWindow
= NULL
;
894 /* Mouse message process */
897 ( MsgWindow
= UserGetWindowObject(Msg
->Msg
.hwnd
) ) &&
898 Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
899 Msg
->Msg
.message
<= WM_MOUSELAST
)
903 UserRefObjectCo(MsgWindow
, &Ref
);
905 if ( co_IntTranslateMouseMessage( ThreadQueue
,
909 /* FIXME - check message filter again, if the message doesn't match anymore,
912 UserDerefObjectCo(MsgWindow
);
913 /* eat the message, search again */
917 if(ThreadQueue
->CaptureWindow
== NULL
)
919 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
921 if ( ( Msg
->Msg
.message
!= WM_MOUSEMOVE
&&
922 Msg
->Msg
.message
!= WM_NCMOUSEMOVE
) &&
923 IS_BTN_MESSAGE(Msg
->Msg
.message
, DOWN
) &&
924 co_IntActivateWindowMouse(ThreadQueue
, &Msg
->Msg
, MsgWindow
, &HitTest
) )
926 UserDerefObjectCo(MsgWindow
);
927 /* eat the message, search again */
932 UserDerefObjectCo(MsgWindow
);
936 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
941 // UserDereferenceObject(MsgWindow);
947 if ( ( Msg
->Msg
.hwnd
&&
948 Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
949 Msg
->Msg
.message
<= WM_MOUSELAST
) &&
950 co_IntTranslateMouseMessage( ThreadQueue
,
954 /* FIXME - check message filter again, if the message doesn't match anymore,
957 /* eat the message, search again */
962 if ( ISITHOOKED(WH_MOUSE
) && IS_MOUSE_MESSAGE(Msg
->Msg
.message
))
964 if(!ProcessMouseMessage(&Msg
->Msg
, HitTest
, RemoveMsg
))
970 if ( ISITHOOKED(WH_KEYBOARD
) && IS_KBD_MESSAGE(Msg
->Msg
.message
))
972 if(!ProcessKeyboardMessage(&Msg
->Msg
, RemoveMsg
))
977 // The WH_GETMESSAGE hook enables an application to monitor messages about to
978 // be returned by the GetMessage or PeekMessage function.
979 if (ISITHOOKED(WH_GETMESSAGE
))
981 //DPRINT1("Peek WH_GETMESSAGE -> %x\n",&Msg);
982 co_HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, RemoveMsg
& PM_REMOVE
, (LPARAM
)&Msg
->Msg
);
990 static NTSTATUS FASTCALL
991 CopyMsgToKernelMem(MSG
*KernelModeMsg
, MSG
*UserModeMsg
, PMSGMEMORY MsgMemoryEntry
)
998 *KernelModeMsg
= *UserModeMsg
;
1000 /* See if this message type is present in the table */
1001 if (NULL
== MsgMemoryEntry
)
1003 /* Not present, no copying needed */
1004 return STATUS_SUCCESS
;
1007 /* Determine required size */
1008 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
1012 /* Allocate kernel mem */
1013 KernelMem
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
1014 if (NULL
== KernelMem
)
1016 DPRINT1("Not enough memory to copy message to kernel mem\n");
1017 return STATUS_NO_MEMORY
;
1019 KernelModeMsg
->lParam
= (LPARAM
) KernelMem
;
1021 /* Copy data if required */
1022 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_READ
))
1024 Status
= MmCopyFromCaller(KernelMem
, (PVOID
) UserModeMsg
->lParam
, Size
);
1025 if (! NT_SUCCESS(Status
))
1027 DPRINT1("Failed to copy message to kernel: invalid usermode buffer\n");
1028 ExFreePoolWithTag(KernelMem
, TAG_MSG
);
1034 /* Make sure we don't pass any secrets to usermode */
1035 RtlZeroMemory(KernelMem
, Size
);
1040 KernelModeMsg
->lParam
= 0;
1043 return STATUS_SUCCESS
;
1046 static NTSTATUS FASTCALL
1047 CopyMsgToUserMem(MSG
*UserModeMsg
, MSG
*KernelModeMsg
)
1050 PMSGMEMORY MsgMemoryEntry
;
1053 /* See if this message type is present in the table */
1054 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
->message
);
1055 if (NULL
== MsgMemoryEntry
)
1057 /* Not present, no copying needed */
1058 return STATUS_SUCCESS
;
1061 /* Determine required size */
1062 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
1066 /* Copy data if required */
1067 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_WRITE
))
1069 Status
= MmCopyToCaller((PVOID
) UserModeMsg
->lParam
, (PVOID
) KernelModeMsg
->lParam
, Size
);
1070 if (! NT_SUCCESS(Status
))
1072 DPRINT1("Failed to copy message from kernel: invalid usermode buffer\n");
1073 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1078 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1081 return STATUS_SUCCESS
;
1084 static BOOL FASTCALL
1085 co_IntWaitMessage( PWINDOW_OBJECT Window
,
1090 PUSER_MESSAGE_QUEUE ThreadQueue
;
1091 NTSTATUS Status
= STATUS_SUCCESS
;
1094 pti
= PsGetCurrentThreadWin32Thread();
1095 ThreadQueue
= pti
->MessageQueue
;
1099 if ( co_IntPeekMessage( &Msg
,
1107 /* Nothing found. Wait for new messages. */
1108 Status
= co_MsqWaitForNewMessages( ThreadQueue
,
1113 while ( (STATUS_WAIT_0
<= Status
&& Status
<= STATUS_WAIT_63
) ||
1114 STATUS_TIMEOUT
== Status
);
1116 if (!NT_SUCCESS(Status
))
1118 SetLastNtError(Status
);
1119 DPRINT1("Exit co_IntWaitMessage on error!\n");
1126 co_IntGetPeekMessage( PMSG pMsg
,
1134 PWINDOW_OBJECT Window
;
1137 if ( hWnd
== HWND_TOPMOST
||
1138 hWnd
== HWND_BROADCAST
)
1141 /* Validate input */
1142 if (hWnd
&& hWnd
!= HWND_BOTTOM
)
1144 if (!(Window
= UserGetWindowObject(hWnd
)))
1154 Window
= (PWINDOW_OBJECT
)hWnd
;
1157 if (MsgFilterMax
< MsgFilterMin
)
1165 Present
= co_IntPeekMessage( &Msg
,
1172 RtlCopyMemory( pMsg
, &Msg
.Msg
, sizeof(MSG
));
1175 return (WM_QUIT
!= pMsg
->message
);
1180 if ( bGMSG
&& !co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
) )
1186 if (!(RemoveMsg
& PM_NOYIELD
))
1188 // Yield this thread!
1191 UserEnterExclusive();
1192 // Fall through to fail.
1196 while( bGMSG
&& !Present
);
1202 UserPostThreadMessage( DWORD idThread
,
1209 PTHREADINFO pThread
;
1210 LARGE_INTEGER LargeTickCount
;
1213 DPRINT1("UserPostThreadMessage wParam 0x%x lParam 0x%x\n", wParam
,lParam
);
1215 if (FindMsgMemory(Msg
) != 0)
1217 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1221 Status
= PsLookupThreadByThreadId((HANDLE
)idThread
,&peThread
);
1223 if( Status
== STATUS_SUCCESS
)
1225 pThread
= (PTHREADINFO
)peThread
->Tcb
.Win32Thread
;
1227 !pThread
->MessageQueue
||
1228 (pThread
->TIF_flags
& TIF_INCLEANUP
))
1230 ObDereferenceObject( peThread
);
1234 Message
.hwnd
= NULL
;
1235 Message
.message
= Msg
;
1236 Message
.wParam
= wParam
;
1237 Message
.lParam
= lParam
;
1238 Message
.pt
= gpsi
->ptCursor
;
1240 KeQueryTickCount(&LargeTickCount
);
1241 pThread
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1242 MsqPostMessage(pThread
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1243 ObDereferenceObject( peThread
);
1248 SetLastNtError( Status
);
1254 UserPostMessage( HWND Wnd
,
1261 LARGE_INTEGER LargeTickCount
;
1263 if (FindMsgMemory(Msg
) != 0)
1265 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1270 return UserPostThreadMessage( PtrToInt(PsGetCurrentThreadId()),
1275 if (Wnd
== HWND_BROADCAST
)
1278 PWINDOW_OBJECT DesktopWindow
;
1281 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1282 List
= IntWinListChildren(DesktopWindow
);
1286 for (i
= 0; List
[i
]; i
++)
1287 UserPostMessage(List
[i
], Msg
, wParam
, lParam
);
1293 PWINDOW_OBJECT Window
;
1295 Window
= UserGetWindowObject(Wnd
);
1296 if ( !Window
|| !Window
->Wnd
)
1301 pti
= Window
->Wnd
->head
.pti
;
1302 if ( pti
->TIF_flags
& TIF_INCLEANUP
)
1304 DPRINT1("Attempted to post message to window 0x%x when the thread is in cleanup!\n", Wnd
);
1308 if ( Window
->state
& WINDOWSTATUS_DESTROYING
)
1310 DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd
);
1311 /* FIXME - last error code? */
1317 MsqPostQuitMessage(Window
->pti
->MessageQueue
, wParam
);
1322 Message
.message
= Msg
;
1323 Message
.wParam
= wParam
;
1324 Message
.lParam
= lParam
;
1325 Message
.pt
= gpsi
->ptCursor
;
1326 KeQueryTickCount(&LargeTickCount
);
1327 pti
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1328 MsqPostMessage(Window
->pti
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1336 co_IntSendMessage( HWND hWnd
,
1341 ULONG_PTR Result
= 0;
1342 if(co_IntSendMessageTimeout(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
))
1344 return (LRESULT
)Result
;
1351 co_IntSendMessageTimeoutSingle( HWND hWnd
,
1357 ULONG_PTR
*uResult
)
1361 PWINDOW_OBJECT Window
= NULL
;
1362 PMSGMEMORY MsgMemoryEntry
;
1363 INT lParamBufferSize
;
1364 LPARAM lParamPacked
;
1365 PTHREADINFO Win32Thread
;
1366 DECLARE_RETURN(LRESULT
);
1367 USER_REFERENCE_ENTRY Ref
;
1369 if (!(Window
= UserGetWindowObject(hWnd
)))
1374 UserRefObjectCo(Window
, &Ref
);
1376 Win32Thread
= PsGetCurrentThreadWin32Thread();
1378 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1380 if ( NULL
!= Win32Thread
&&
1381 Window
->pti
->MessageQueue
== Win32Thread
->MessageQueue
)
1383 if (Win32Thread
->TIF_flags
& TIF_INCLEANUP
)
1385 /* Never send messages to exiting threads */
1389 /* See if this message type is present in the table */
1390 MsgMemoryEntry
= FindMsgMemory(Msg
);
1391 if (NULL
== MsgMemoryEntry
)
1393 lParamBufferSize
= -1;
1397 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1400 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
, FALSE
)))
1402 DPRINT1("Failed to pack message parameters\n");
1406 Result
= (ULONG_PTR
)co_IntCallWindowProc( Window
->Wnd
->lpfnWndProc
,
1407 !Window
->Wnd
->Unicode
,
1418 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1420 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
, FALSE
)))
1422 DPRINT1("Failed to unpack message parameters\n");
1429 if (uFlags
& SMTO_ABORTIFHUNG
&& MsqIsHung(Window
->pti
->MessageQueue
))
1431 /* FIXME - Set a LastError? */
1435 if (Window
->state
& WINDOWSTATUS_DESTROYING
)
1437 /* FIXME - last error? */
1438 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1444 Status
= co_MsqSendMessage( Window
->pti
->MessageQueue
,
1450 (uFlags
& SMTO_BLOCK
),
1454 while ((STATUS_TIMEOUT
== Status
) &&
1455 (uFlags
& SMTO_NOTIMEOUTIFNOTHUNG
) &&
1456 !MsqIsHung(Window
->pti
->MessageQueue
));
1458 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1460 if (STATUS_TIMEOUT
== Status
)
1464 Microsoft Windows 2000: If GetLastError returns zero, then the function
1466 XP+ : If the function fails or times out, the return value is zero.
1467 To get extended error information, call GetLastError. If GetLastError
1468 returns ERROR_TIMEOUT, then the function timed out.
1470 SetLastWin32Error(ERROR_TIMEOUT
);
1473 else if (! NT_SUCCESS(Status
))
1475 SetLastNtError(Status
);
1482 if (Window
) UserDerefObjectCo(Window
);
1487 co_IntSendMessageTimeout( HWND hWnd
,
1493 ULONG_PTR
*uResult
)
1495 PWINDOW_OBJECT DesktopWindow
;
1499 if (HWND_BROADCAST
!= hWnd
)
1501 return co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1504 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1505 if (NULL
== DesktopWindow
)
1507 SetLastWin32Error(ERROR_INTERNAL_ERROR
);
1511 Children
= IntWinListChildren(DesktopWindow
);
1512 if (NULL
== Children
)
1517 for (Child
= Children
; NULL
!= *Child
; Child
++)
1519 co_IntSendMessageTimeoutSingle(*Child
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1522 ExFreePool(Children
);
1524 return (LRESULT
) TRUE
;
1527 LRESULT FASTCALL
co_IntSendMessageNoWait(HWND hWnd
,
1532 ULONG_PTR Result
= 0;
1533 co_IntSendMessageWithCallBack(hWnd
,
1544 co_IntSendMessageWithCallBack( HWND hWnd
,
1548 SENDASYNCPROC CompletionCallback
,
1549 ULONG_PTR CompletionCallbackContext
,
1553 PWINDOW_OBJECT Window
= NULL
;
1554 PMSGMEMORY MsgMemoryEntry
;
1555 INT lParamBufferSize
;
1556 LPARAM lParamPacked
;
1557 PTHREADINFO Win32Thread
;
1558 DECLARE_RETURN(LRESULT
);
1559 USER_REFERENCE_ENTRY Ref
;
1560 PUSER_SENT_MESSAGE Message
;
1562 if (!(Window
= UserGetWindowObject(hWnd
)))
1567 UserRefObjectCo(Window
, &Ref
);
1569 if (Window
->state
& WINDOWSTATUS_DESTROYING
)
1571 /* FIXME - last error? */
1572 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1576 Win32Thread
= PsGetCurrentThreadWin32Thread();
1578 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1580 if (Win32Thread
== NULL
)
1586 if (Win32Thread
->TIF_flags
& TIF_INCLEANUP
)
1588 /* Never send messages to exiting threads */
1592 /* See if this message type is present in the table */
1593 MsgMemoryEntry
= FindMsgMemory(Msg
);
1594 if (NULL
== MsgMemoryEntry
)
1596 lParamBufferSize
= -1;
1600 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1603 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
, Window
->pti
->MessageQueue
!= Win32Thread
->MessageQueue
)))
1605 DPRINT1("Failed to pack message parameters\n");
1609 /* If this is not a callback and it can be sent now, then send it. */
1610 if ((Window
->pti
->MessageQueue
== Win32Thread
->MessageQueue
) && (CompletionCallback
== NULL
))
1613 Result
= (ULONG_PTR
)co_IntCallWindowProc( Window
->Wnd
->lpfnWndProc
,
1614 !Window
->Wnd
->Unicode
,
1626 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1628 if ((Window
->pti
->MessageQueue
== Win32Thread
->MessageQueue
) && (CompletionCallback
== NULL
))
1630 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
, FALSE
)))
1632 DPRINT1("Failed to unpack message parameters\n");
1637 if(!(Message
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(USER_SENT_MESSAGE
), TAG_USRMSG
)))
1639 DPRINT1("MsqSendMessage(): Not enough memory to allocate a message");
1640 return STATUS_INSUFFICIENT_RESOURCES
;
1643 Message
->Msg
.hwnd
= hWnd
;
1644 Message
->Msg
.message
= Msg
;
1645 Message
->Msg
.wParam
= wParam
;
1646 Message
->Msg
.lParam
= lParamPacked
;
1647 Message
->CompletionEvent
= NULL
;
1648 Message
->Result
= 0;
1649 Message
->SenderQueue
= NULL
; //Win32Thread->MessageQueue;
1651 IntReferenceMessageQueue(Window
->pti
->MessageQueue
);
1652 Message
->CompletionCallback
= CompletionCallback
;
1653 Message
->CompletionCallbackContext
= CompletionCallbackContext
;
1654 Message
->HookMessage
= MSQ_NORMAL
| MSQ_SENTNOWAIT
;
1655 Message
->HasPackedLParam
= (lParamBufferSize
> 0);
1657 InsertTailList(&Window
->pti
->MessageQueue
->SentMessagesListHead
, &Message
->ListEntry
);
1658 IntDereferenceMessageQueue(Window
->pti
->MessageQueue
);
1663 if (Window
) UserDerefObjectCo(Window
);
1667 /* This function posts a message if the destination's message queue belongs to
1668 another thread, otherwise it sends the message. It does not support broadcast
1671 co_IntPostOrSendMessage( HWND hWnd
,
1678 PWINDOW_OBJECT Window
;
1680 if ( hWnd
== HWND_BROADCAST
)
1685 if(!(Window
= UserGetWindowObject(hWnd
)))
1690 pti
= PsGetCurrentThreadWin32Thread();
1692 if ( Window
->pti
->MessageQueue
!= pti
->MessageQueue
&&
1693 FindMsgMemory(Msg
) == 0 )
1695 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1699 if ( !co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
) )
1705 return (LRESULT
)Result
;
1709 co_IntDoSendMessage( HWND hWnd
,
1714 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1717 LRESULT Result
= TRUE
;
1719 PWINDOW_OBJECT Window
= NULL
;
1720 NTUSERSENDMESSAGEINFO Info
;
1723 PMSGMEMORY MsgMemoryEntry
;
1725 RtlZeroMemory(&Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1727 /* FIXME: Call hooks. */
1728 if (HWND_BROADCAST
!= hWnd
)
1730 Window
= UserGetWindowObject(hWnd
);
1731 if ( !Window
|| !Window
->Wnd
)
1733 /* Tell usermode to not touch this one */
1734 Info
.HandledByKernel
= TRUE
;
1735 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1740 /* Check for an exiting window. */
1741 if (Window
&& Window
->state
& WINDOWSTATUS_DESTROYING
)
1743 DPRINT1("co_IntDoSendMessage Window Exiting!\n");
1746 /* See if the current thread can handle the message */
1747 pti
= PsGetCurrentThreadWin32Thread();
1749 // This is checked in user mode!!!!!!!
1750 if ( HWND_BROADCAST
!= hWnd
&&
1752 Window
->pti
->MessageQueue
== pti
->MessageQueue
&&
1753 !ISITHOOKED(WH_CALLWNDPROC
) &&
1754 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
1755 ( Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
) )
1757 /* Gather the information usermode needs to call the window proc directly */
1758 Info
.HandledByKernel
= FALSE
;
1760 Status
= MmCopyFromCaller(&(Info
.Ansi
), &(UnsafeInfo
->Ansi
),
1762 if (! NT_SUCCESS(Status
))
1764 Info
.Ansi
= ! Window
->Wnd
->Unicode
;
1767 Info
.Ansi
= !Window
->Wnd
->Unicode
;
1768 Info
.Proc
= Window
->Wnd
->lpfnWndProc
;
1772 /* Must be handled by other thread */
1773 // if (HWND_BROADCAST != hWnd)
1775 // UserDereferenceObject(Window);
1777 Info
.HandledByKernel
= TRUE
;
1778 UserModeMsg
.hwnd
= hWnd
;
1779 UserModeMsg
.message
= Msg
;
1780 UserModeMsg
.wParam
= wParam
;
1781 UserModeMsg
.lParam
= lParam
;
1782 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1784 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1785 if (! NT_SUCCESS(Status
))
1787 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1788 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1789 return (dsm
? 0 : -1);
1794 Result
= co_IntSendMessage( KernelModeMsg
.hwnd
,
1795 KernelModeMsg
.message
,
1796 KernelModeMsg
.wParam
,
1797 KernelModeMsg
.lParam
);
1801 Result
= co_IntSendMessageTimeout( KernelModeMsg
.hwnd
,
1802 KernelModeMsg
.message
,
1803 KernelModeMsg
.wParam
,
1804 KernelModeMsg
.lParam
,
1810 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1811 if (! NT_SUCCESS(Status
))
1813 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1814 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1815 return(dsm
? 0 : -1);
1819 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1820 if (! NT_SUCCESS(Status
))
1822 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1825 return (LRESULT
)Result
;
1830 UserSendNotifyMessage( HWND hWnd
,
1837 if (FindMsgMemory(Msg
) != 0)
1839 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1843 // Basicly the same as IntPostOrSendMessage
1844 if (hWnd
== HWND_BROADCAST
) //Handle Broadcast
1847 PWINDOW_OBJECT DesktopWindow
;
1850 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1851 List
= IntWinListChildren(DesktopWindow
);
1855 for (i
= 0; List
[i
]; i
++)
1857 UserSendNotifyMessage(List
[i
], Msg
, wParam
, lParam
);
1866 PWINDOW_OBJECT Window
;
1869 if ( !(Window
= UserGetWindowObject(hWnd
)) ) return FALSE
;
1871 pti
= PsGetCurrentThreadWin32Thread();
1873 if (Window
->pti
->MessageQueue
!= pti
->MessageQueue
)
1874 { // Send message w/o waiting for it.
1875 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1878 { // Handle message and callback.
1879 Message
.hwnd
= hWnd
;
1880 Message
.message
= Msg
;
1881 Message
.wParam
= wParam
;
1882 Message
.lParam
= lParam
;
1884 Result
= co_IntSendMessageTimeoutSingle( hWnd
,
1898 IntGetQueueStatus(BOOL ClearChanges
)
1901 PUSER_MESSAGE_QUEUE Queue
;
1903 DECLARE_RETURN(DWORD
);
1905 DPRINT("Enter IntGetQueueStatus\n");
1907 pti
= PsGetCurrentThreadWin32Thread();
1908 Queue
= pti
->MessageQueue
;
1910 Result
= MAKELONG(Queue
->QueueBits
, Queue
->ChangedBits
);
1913 Queue
->ChangedBits
= 0;
1919 DPRINT("Leave IntGetQueueStatus, ret=%i\n",_ret_
);
1924 IntInitMessagePumpHook()
1926 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1928 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
++;
1935 IntUninitMessagePumpHook()
1937 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1939 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
<= 0)
1943 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
--;
1949 /** Functions ******************************************************************/
1952 NtUserPostMessage(HWND hWnd
,
1957 DECLARE_RETURN(BOOL
);
1959 DPRINT("Enter NtUserPostMessage\n");
1960 UserEnterExclusive();
1962 RETURN( UserPostMessage(hWnd
, Msg
, wParam
, lParam
));
1965 DPRINT("Leave NtUserPostMessage, ret=%i\n",_ret_
);
1971 NtUserPostThreadMessage(DWORD idThread
,
1976 DECLARE_RETURN(BOOL
);
1978 DPRINT("Enter NtUserPostThreadMessage\n");
1979 UserEnterExclusive();
1981 RETURN( UserPostThreadMessage( idThread
,
1987 DPRINT("Leave NtUserPostThreadMessage, ret=%i\n",_ret_
);
1993 NtUserQuerySendMessage(DWORD Unknown0
)
2001 ////////// API on the way out!
2003 NtUserSendMessageTimeout( HWND hWnd
,
2010 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
2014 DECLARE_RETURN(BOOL
);
2016 DPRINT("Enter NtUserSendMessageTimeout\n");
2017 UserEnterExclusive();
2019 dsm
.uFlags
= uFlags
;
2020 dsm
.uTimeout
= uTimeout
;
2021 Result
= co_IntDoSendMessage(hWnd
, Msg
, wParam
, lParam
, &dsm
, UnsafeInfo
);
2022 if(uResult
!= NULL
&& Result
!= 0)
2026 Status
= MmCopyToCaller(uResult
, &dsm
.Result
, sizeof(ULONG_PTR
));
2027 if(!NT_SUCCESS(Status
))
2029 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2036 DPRINT("Leave NtUserSendMessageTimeout, ret=%i\n",_ret_
);
2042 NtUserSendMessage( HWND Wnd
,
2046 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
2048 DECLARE_RETURN(BOOL
);
2050 DPRINT("Enter NtUserSendMessage\n");
2051 UserEnterExclusive();
2053 RETURN(co_IntDoSendMessage(Wnd
, Msg
, wParam
, lParam
, NULL
, UnsafeInfo
));
2056 DPRINT("Leave NtUserSendMessage, ret=%i\n",_ret_
);
2063 NtUserWaitMessage(VOID
)
2065 DECLARE_RETURN(BOOL
);
2067 DPRINT("EnterNtUserWaitMessage\n");
2068 UserEnterExclusive();
2070 RETURN(co_IntWaitMessage(NULL
, 0, 0));
2073 DPRINT("Leave NtUserWaitMessage, ret=%i\n",_ret_
);
2080 NtUserGetMessage( PNTUSERGETMESSAGEINFO UnsafeInfo
,
2085 * FUNCTION: Get a message from the calling thread's message queue.
2087 * UnsafeMsg - Pointer to the structure which receives the returned message.
2088 * Wnd - Window whose messages are to be retrieved.
2089 * MsgFilterMin - Integer value of the lowest message value to be
2091 * MsgFilterMax - Integer value of the highest message value to be
2096 NTUSERGETMESSAGEINFO Info
;
2098 /* FIXME: if initialization is removed, gcc complains that this may be used before initialization. Please review */
2099 PWINDOW_OBJECT Window
= NULL
;
2100 PMSGMEMORY MsgMemoryEntry
;
2104 DECLARE_RETURN(BOOL
);
2105 // USER_REFERENCE_ENTRY Ref;
2107 DPRINT("Enter NtUserGetMessage\n");
2108 UserEnterExclusive();
2110 /* Validate input */
2111 if (hWnd
&& !(Window
= UserGetWindowObject(hWnd
)))
2116 // if (Window) UserRefObjectCo(Window, &Ref);
2118 if (MsgFilterMax
< MsgFilterMin
)
2126 GotMessage
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
);
2130 /* See if this message type is present in the table */
2131 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
2132 if (NULL
== MsgMemoryEntry
)
2134 /* Not present, no copying needed */
2135 Info
.LParamSize
= 0;
2139 /* Determine required size */
2140 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
2142 /* Allocate required amount of user-mode memory */
2143 Info
.LParamSize
= Size
;
2145 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
2146 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
2148 if (! NT_SUCCESS(Status
))
2150 SetLastNtError(Status
);
2153 /* Transfer lParam data to user-mode mem */
2154 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
2155 if (! NT_SUCCESS(Status
))
2157 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
2158 &Info
.LParamSize
, MEM_DECOMMIT
);
2159 SetLastNtError(Status
);
2162 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
2164 if (Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
2166 ExFreePool((void *) Msg
.Msg
.lParam
);
2168 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
2169 if (! NT_SUCCESS(Status
))
2171 SetLastNtError(Status
);
2175 else if (! co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
))
2180 while (! GotMessage
);
2182 RETURN( WM_QUIT
!= Info
.Msg
.message
);
2185 // if (Window) UserDerefObjectCo(Window);
2187 DPRINT("Leave NtUserGetMessage\n");
2203 DECLARE_RETURN(BOOL
);
2205 DPRINT("Enter NtUserGetMessage\n");
2206 UserEnterExclusive();
2208 if ( (MsgFilterMin
|MsgFilterMax
) & ~WM_MAXIMUM
)
2210 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2214 RtlZeroMemory(&Msg
, sizeof(MSG
));
2216 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
, TRUE
);
2222 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
2223 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
2225 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2227 SetLastNtError(_SEH2_GetExceptionCode());
2235 DPRINT("Leave NtUserGetMessage\n");
2241 NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
2249 NTUSERGETMESSAGEINFO Info
;
2250 PWINDOW_OBJECT Window
;
2251 PMSGMEMORY MsgMemoryEntry
;
2255 DECLARE_RETURN(BOOL
);
2257 DPRINT("Enter NtUserPeekMessage\n");
2258 UserEnterExclusive();
2260 if (hWnd
== (HWND
)-1 || hWnd
== (HWND
)0x0000FFFF || hWnd
== (HWND
)0xFFFFFFFF)
2263 /* Validate input */
2264 if (hWnd
&& hWnd
!= (HWND
)1)
2266 if (!(Window
= UserGetWindowObject(hWnd
)))
2273 Window
= (PWINDOW_OBJECT
)hWnd
;
2276 if (MsgFilterMax
< MsgFilterMin
)
2282 Present
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
);
2287 /* See if this message type is present in the table */
2288 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
2289 if (NULL
== MsgMemoryEntry
)
2291 /* Not present, no copying needed */
2292 Info
.LParamSize
= 0;
2296 /* Determine required size */
2297 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
2299 /* Allocate required amount of user-mode memory */
2300 Info
.LParamSize
= Size
;
2302 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
2303 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
2304 if (! NT_SUCCESS(Status
))
2306 SetLastNtError(Status
);
2309 /* Transfer lParam data to user-mode mem */
2310 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
2311 if (! NT_SUCCESS(Status
))
2313 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
2314 &Info
.LParamSize
, MEM_RELEASE
);
2315 SetLastNtError(Status
);
2318 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
2320 if (RemoveMsg
&& Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
2322 ExFreePool((void *) Msg
.Msg
.lParam
);
2324 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
2325 if (! NT_SUCCESS(Status
))
2327 SetLastNtError(Status
);
2335 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2351 DECLARE_RETURN(BOOL
);
2353 DPRINT("Enter NtUserPeekMessage\n");
2354 UserEnterExclusive();
2356 if ( RemoveMsg
& PM_BADMSGFLAGS
)
2358 SetLastWin32Error(ERROR_INVALID_FLAGS
);
2362 RtlZeroMemory(&Msg
, sizeof(MSG
));
2364 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
, FALSE
);
2370 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
2371 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
2373 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2375 SetLastNtError(_SEH2_GetExceptionCode());
2383 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2390 NtUserCallMsgFilter(
2394 BOOL BadChk
= FALSE
, Ret
= FALSE
;
2396 DECLARE_RETURN(BOOL
);
2398 DPRINT("Enter NtUserCallMsgFilter\n");
2399 UserEnterExclusive();
2404 ProbeForRead((PVOID
)lpmsg
,
2407 RtlCopyMemory( &Msg
,
2411 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2420 if (BadChk
) RETURN( FALSE
);
2422 if ( ISITHOOKED(WH_SYSMSGFILTER
) &&
2423 co_HOOK_CallHooks( WH_SYSMSGFILTER
, code
, 0, (LPARAM
)&Msg
))
2429 if ( ISITHOOKED(WH_MSGFILTER
) )
2431 Ret
= co_HOOK_CallHooks( WH_MSGFILTER
, code
, 0, (LPARAM
)&Msg
);
2437 ProbeForWrite((PVOID
)lpmsg
,
2440 RtlCopyMemory((PVOID
)lpmsg
,
2444 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2449 if (BadChk
) RETURN( FALSE
);
2453 DPRINT("Leave NtUserCallMsgFilter. ret=%i\n", _ret_
);
2459 NtUserDispatchMessage(PMSG UnsafeMsgInfo
)
2465 UserEnterExclusive();
2468 ProbeForRead(UnsafeMsgInfo
, sizeof(MSG
), 1);
2469 RtlCopyMemory(&SafeMsg
, UnsafeMsgInfo
, sizeof(MSG
));
2471 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2473 SetLastNtError(_SEH2_GetExceptionCode());
2478 if (!Hit
) Res
= IntDispatchMessage(&SafeMsg
);
2486 NtUserTranslateMessage(LPMSG lpMsg
,
2491 DECLARE_RETURN(BOOL
);
2493 DPRINT("Enter NtUserTranslateMessage\n");
2494 UserEnterExclusive();
2496 Status
= MmCopyFromCaller(&SafeMsg
, lpMsg
, sizeof(MSG
));
2497 if(!NT_SUCCESS(Status
))
2499 SetLastNtError(Status
);
2503 RETURN( IntTranslateKbdMessage(&SafeMsg
, flags
));
2506 DPRINT("Leave NtUserTranslateMessage: ret=%i\n",_ret_
);
2517 ULONG_PTR ResultInfo
,
2518 DWORD dwType
, // fnID?
2521 LRESULT lResult
= 0;
2523 BOOL BadChk
= FALSE
;
2524 PWINDOW_OBJECT Window
= NULL
;
2525 USER_REFERENCE_ENTRY Ref
;
2527 UserEnterExclusive();
2529 /* Validate input */
2530 if (hWnd
&& (hWnd
!= INVALID_HANDLE_VALUE
) && !(Window
= UserGetWindowObject(hWnd
)))
2537 case FNID_DEFWINDOWPROC
:
2538 UserRefObjectCo(Window
, &Ref
);
2539 lResult
= IntDefWindowProc(Window
, Msg
, wParam
, lParam
, Ansi
);
2541 UserDerefObjectCo(Window
);
2543 case FNID_SENDNOTIFYMESSAGE
:
2544 Ret
= UserSendNotifyMessage(hWnd
, Msg
, wParam
, lParam
);
2546 case FNID_BROADCASTSYSTEMMESSAGE
:
2549 DWORD_PTR RetVal
= 0;
2555 ProbeForWrite((PVOID
)ResultInfo
,
2556 sizeof(BROADCASTPARM
),
2558 RtlCopyMemory(&parm
, (PVOID
)ResultInfo
, sizeof(BROADCASTPARM
));
2560 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2570 if ( parm
.recipients
& BSM_ALLDESKTOPS
||
2571 parm
.recipients
== BSM_ALLCOMPONENTS
)
2574 else if (parm
.recipients
& BSM_APPLICATIONS
)
2576 if (parm
.flags
& BSF_QUERY
)
2578 if (parm
.flags
& BSF_FORCEIFHUNG
|| parm
.flags
& BSF_NOHANG
)
2580 co_IntSendMessageTimeout( HWND_BROADCAST
,
2588 else if (parm
.flags
& BSF_NOTIMEOUTIFNOTHUNG
)
2590 co_IntSendMessageTimeout( HWND_BROADCAST
,
2594 SMTO_NOTIMEOUTIFNOTHUNG
,
2600 co_IntSendMessageTimeout( HWND_BROADCAST
,
2609 else if (parm
.flags
& BSF_POSTMESSAGE
)
2611 Ret
= UserPostMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2613 else if ( parm
.flags
& BSF_SENDNOTIFYMESSAGE
)
2615 Ret
= UserSendNotifyMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2620 case FNID_SENDMESSAGECALLBACK
:
2622 PCALL_BACK_INFO CallBackInfo
= (PCALL_BACK_INFO
)ResultInfo
;
2627 if (!co_IntSendMessageWithCallBack(hWnd
, Msg
, wParam
, lParam
,
2628 CallBackInfo
->CallBack
, CallBackInfo
->Context
, NULL
))
2630 DPRINT1("Callback failure!\n");
2634 // CallNextHook bypass.
2635 case FNID_CALLWNDPROC
:
2636 case FNID_CALLWNDPROCRET
:
2638 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
2639 PHOOK NextObj
, Hook
= ClientInfo
->phkCurrent
;
2641 if (!ClientInfo
|| !Hook
) break;
2643 UserReferenceObject(Hook
);
2645 if (Hook
->Thread
&& (Hook
->Thread
!= PsGetCurrentThread()))
2647 UserDereferenceObject(Hook
);
2651 NextObj
= IntGetNextHook(Hook
);
2652 ClientInfo
->phkCurrent
= NextObj
;
2654 if ( Hook
->HookId
== WH_CALLWNDPROC
)
2659 CWP
.wParam
= wParam
;
2660 CWP
.lParam
= lParam
;
2661 DPRINT("WH_CALLWNDPROC: Hook %x NextHook %x\n", Hook
, NextObj
);
2663 lResult
= co_IntCallHookProc( Hook
->HookId
,
2665 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2676 CWPR
.wParam
= wParam
;
2677 CWPR
.lParam
= lParam
;
2678 CWPR
.lResult
= ClientInfo
->dwHookData
;
2680 lResult
= co_IntCallHookProc( Hook
->HookId
,
2682 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2688 UserDereferenceObject(Hook
);
2689 lResult
= (LRESULT
) NextObj
;
2696 case FNID_DEFWINDOWPROC
:
2697 case FNID_CALLWNDPROC
:
2698 case FNID_CALLWNDPROCRET
:
2703 ProbeForWrite((PVOID
)ResultInfo
, sizeof(LRESULT
), 1);
2704 RtlCopyMemory((PVOID
)ResultInfo
, &lResult
, sizeof(LRESULT
));
2706 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2719 return BadChk
? FALSE
: Ret
;
2722 #define INFINITE 0xFFFFFFFF
2723 #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
2727 NtUserWaitForInputIdle(
2729 IN DWORD dwMilliseconds
,
2733 PPROCESSINFO W32Process
;
2736 LARGE_INTEGER Timeout
;
2737 ULONGLONG StartTime
, Run
, Elapsed
= 0;
2739 UserEnterExclusive();
2741 Status
= ObReferenceObjectByHandle(hProcess
,
2742 PROCESS_QUERY_INFORMATION
,
2748 if (!NT_SUCCESS(Status
))
2751 SetLastNtError(Status
);
2755 W32Process
= (PPROCESSINFO
)Process
->Win32Process
;
2758 ObDereferenceObject(Process
);
2760 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2764 EngCreateEvent((PEVENT
*)&W32Process
->InputIdleEvent
);
2766 Handles
[0] = Process
;
2767 Handles
[1] = W32Process
->InputIdleEvent
;
2771 ObDereferenceObject(Process
);
2773 return STATUS_SUCCESS
; /* no event to wait on */
2776 StartTime
= EngGetTickCount();
2778 Run
= dwMilliseconds
;
2780 DPRINT("WFII: waiting for %p\n", Handles
[1] );
2783 Timeout
.QuadPart
= Run
- Elapsed
;
2785 Status
= KeWaitForMultipleObjects( 2,
2791 dwMilliseconds
== INFINITE
? NULL
: &Timeout
,
2793 UserEnterExclusive();
2795 if (!NT_SUCCESS(Status
))
2797 SetLastNtError(Status
);
2798 Status
= WAIT_FAILED
;
2805 Status
= WAIT_FAILED
;
2811 co_IntPeekMessage( &Msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2815 case STATUS_USER_APC
:
2816 case STATUS_ALERTED
:
2817 case STATUS_TIMEOUT
:
2818 DPRINT1("WFII: timeout\n");
2819 Status
= STATUS_TIMEOUT
;
2823 DPRINT1("WFII: finished\n");
2824 Status
= STATUS_SUCCESS
;
2828 if (dwMilliseconds
!= INFINITE
)
2830 Elapsed
= EngGetTickCount() - StartTime
;
2833 Status
= STATUS_TIMEOUT
;
2840 if (W32Process
->InputIdleEvent
)
2842 EngFreeMem((PVOID
)W32Process
->InputIdleEvent
);
2843 W32Process
->InputIdleEvent
= NULL
;
2845 ObDereferenceObject(Process
);