2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
23 * FILE: subsys/win32k/ntuser/message.c
24 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 06-06-2001 CSH Created
29 /* INCLUDES ******************************************************************/
42 DOSENDMESSAGE
, *PDOSENDMESSAGE
;
44 /* FUNCTIONS *****************************************************************/
47 IntInitMessageImpl(VOID
)
49 return STATUS_SUCCESS
;
53 IntCleanupMessageImpl(VOID
)
55 return STATUS_SUCCESS
;
58 #define MMS_SIZE_WPARAM -1
59 #define MMS_SIZE_WPARAMWCHAR -2
60 #define MMS_SIZE_LPARAMSZ -3
61 #define MMS_SIZE_SPECIAL -4
62 #define MMS_FLAG_READ 0x01
63 #define MMS_FLAG_WRITE 0x02
64 #define MMS_FLAG_READWRITE (MMS_FLAG_READ | MMS_FLAG_WRITE)
65 typedef struct tagMSGMEMORY
71 MSGMEMORY
, *PMSGMEMORY
;
73 static MSGMEMORY MsgMemory
[] =
75 { WM_CREATE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
76 { WM_DDE_ACK
, sizeof(KMDDELPARAM
), MMS_FLAG_READ
},
77 { WM_DDE_EXECUTE
, MMS_SIZE_WPARAM
, MMS_FLAG_READ
},
78 { WM_GETMINMAXINFO
, sizeof(MINMAXINFO
), MMS_FLAG_READWRITE
},
79 { WM_GETTEXT
, MMS_SIZE_WPARAMWCHAR
, MMS_FLAG_WRITE
},
80 { WM_NCCALCSIZE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
81 { WM_NCCREATE
, MMS_SIZE_SPECIAL
, MMS_FLAG_READWRITE
},
82 { WM_SETTEXT
, MMS_SIZE_LPARAMSZ
, MMS_FLAG_READ
},
83 { WM_STYLECHANGED
, sizeof(STYLESTRUCT
), MMS_FLAG_READ
},
84 { WM_STYLECHANGING
, sizeof(STYLESTRUCT
), MMS_FLAG_READWRITE
},
85 { WM_COPYDATA
, MMS_SIZE_SPECIAL
, MMS_FLAG_READ
},
86 { WM_WINDOWPOSCHANGED
, sizeof(WINDOWPOS
), MMS_FLAG_READ
},
87 { WM_WINDOWPOSCHANGING
, sizeof(WINDOWPOS
), MMS_FLAG_READWRITE
},
90 static PMSGMEMORY FASTCALL
91 FindMsgMemory(UINT Msg
)
93 PMSGMEMORY MsgMemoryEntry
;
95 /* See if this message type is present in the table */
96 for (MsgMemoryEntry
= MsgMemory
;
97 MsgMemoryEntry
< MsgMemory
+ sizeof(MsgMemory
) / sizeof(MSGMEMORY
);
100 if (Msg
== MsgMemoryEntry
->Message
)
102 return MsgMemoryEntry
;
110 MsgMemorySize(PMSGMEMORY MsgMemoryEntry
, WPARAM wParam
, LPARAM lParam
)
113 PUNICODE_STRING WindowName
;
114 PUNICODE_STRING ClassName
;
119 if (MMS_SIZE_WPARAM
== MsgMemoryEntry
->Size
)
123 else if (MMS_SIZE_WPARAMWCHAR
== MsgMemoryEntry
->Size
)
125 Size
= (UINT
) (wParam
* sizeof(WCHAR
));
127 else if (MMS_SIZE_LPARAMSZ
== MsgMemoryEntry
->Size
)
129 Size
= (UINT
) ((wcslen((PWSTR
) lParam
) + 1) * sizeof(WCHAR
));
131 else if (MMS_SIZE_SPECIAL
== MsgMemoryEntry
->Size
)
133 switch(MsgMemoryEntry
->Message
)
137 Cs
= (CREATESTRUCTW
*) lParam
;
138 WindowName
= (PUNICODE_STRING
) Cs
->lpszName
;
139 ClassName
= (PUNICODE_STRING
) Cs
->lpszClass
;
140 Size
= sizeof(CREATESTRUCTW
) + WindowName
->Length
+ sizeof(WCHAR
);
141 if (IS_ATOM(ClassName
->Buffer
))
143 Size
+= sizeof(WCHAR
) + sizeof(ATOM
);
147 Size
+= sizeof(WCHAR
) + ClassName
->Length
+ sizeof(WCHAR
);
152 Size
= wParam
? sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
) : sizeof(RECT
);
156 Size
= sizeof(COPYDATASTRUCT
) + ((PCOPYDATASTRUCT
)lParam
)->cbData
;
167 Size
= MsgMemoryEntry
->Size
;
170 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
172 DPRINT1("Exception caught in MsgMemorySize()! Status: 0x%x\n", _SEH2_GetExceptionCode());
180 PackParam(LPARAM
*lParamPacked
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
182 NCCALCSIZE_PARAMS
*UnpackedNcCalcsize
;
183 NCCALCSIZE_PARAMS
*PackedNcCalcsize
;
184 CREATESTRUCTW
*UnpackedCs
;
185 CREATESTRUCTW
*PackedCs
;
186 PUNICODE_STRING WindowName
;
187 PUNICODE_STRING ClassName
;
191 *lParamPacked
= lParam
;
192 if (WM_NCCALCSIZE
== Msg
&& wParam
)
194 UnpackedNcCalcsize
= (NCCALCSIZE_PARAMS
*) lParam
;
195 if (UnpackedNcCalcsize
->lppos
!= (PWINDOWPOS
) (UnpackedNcCalcsize
+ 1))
197 PackedNcCalcsize
= ExAllocatePoolWithTag(PagedPool
,
198 sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
),
200 if (NULL
== PackedNcCalcsize
)
202 DPRINT1("Not enough memory to pack lParam\n");
203 return STATUS_NO_MEMORY
;
205 RtlCopyMemory(PackedNcCalcsize
, UnpackedNcCalcsize
, sizeof(NCCALCSIZE_PARAMS
));
206 PackedNcCalcsize
->lppos
= (PWINDOWPOS
) (PackedNcCalcsize
+ 1);
207 RtlCopyMemory(PackedNcCalcsize
->lppos
, UnpackedNcCalcsize
->lppos
, sizeof(WINDOWPOS
));
208 *lParamPacked
= (LPARAM
) PackedNcCalcsize
;
211 else if (WM_CREATE
== Msg
|| WM_NCCREATE
== Msg
)
213 UnpackedCs
= (CREATESTRUCTW
*) lParam
;
214 WindowName
= (PUNICODE_STRING
) UnpackedCs
->lpszName
;
215 ClassName
= (PUNICODE_STRING
) UnpackedCs
->lpszClass
;
216 Size
= sizeof(CREATESTRUCTW
) + WindowName
->Length
+ sizeof(WCHAR
);
217 if (IS_ATOM(ClassName
->Buffer
))
219 Size
+= sizeof(WCHAR
) + sizeof(ATOM
);
223 Size
+= sizeof(WCHAR
) + ClassName
->Length
+ sizeof(WCHAR
);
225 PackedCs
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
226 if (NULL
== PackedCs
)
228 DPRINT1("Not enough memory to pack lParam\n");
229 return STATUS_NO_MEMORY
;
231 RtlCopyMemory(PackedCs
, UnpackedCs
, sizeof(CREATESTRUCTW
));
232 CsData
= (PCHAR
) (PackedCs
+ 1);
233 PackedCs
->lpszName
= (LPCWSTR
) (CsData
- (PCHAR
) PackedCs
);
234 RtlCopyMemory(CsData
, WindowName
->Buffer
, WindowName
->Length
);
235 CsData
+= WindowName
->Length
;
236 *((WCHAR
*) CsData
) = L
'\0';
237 CsData
+= sizeof(WCHAR
);
238 PackedCs
->lpszClass
= (LPCWSTR
) (CsData
- (PCHAR
) PackedCs
);
239 if (IS_ATOM(ClassName
->Buffer
))
241 *((WCHAR
*) CsData
) = L
'A';
242 CsData
+= sizeof(WCHAR
);
243 *((ATOM
*) CsData
) = (ATOM
)(DWORD_PTR
) ClassName
->Buffer
;
244 CsData
+= sizeof(ATOM
);
248 *((WCHAR
*) CsData
) = L
'S';
249 CsData
+= sizeof(WCHAR
);
250 RtlCopyMemory(CsData
, ClassName
->Buffer
, ClassName
->Length
);
251 CsData
+= ClassName
->Length
;
252 *((WCHAR
*) CsData
) = L
'\0';
253 CsData
+= sizeof(WCHAR
);
255 ASSERT(CsData
== (PCHAR
) PackedCs
+ Size
);
256 *lParamPacked
= (LPARAM
) PackedCs
;
259 return STATUS_SUCCESS
;
263 UnpackParam(LPARAM lParamPacked
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
265 NCCALCSIZE_PARAMS
*UnpackedParams
;
266 NCCALCSIZE_PARAMS
*PackedParams
;
267 PWINDOWPOS UnpackedWindowPos
;
269 if (lParamPacked
== lParam
)
271 return STATUS_SUCCESS
;
274 if (WM_NCCALCSIZE
== Msg
&& wParam
)
276 PackedParams
= (NCCALCSIZE_PARAMS
*) lParamPacked
;
277 UnpackedParams
= (NCCALCSIZE_PARAMS
*) lParam
;
278 UnpackedWindowPos
= UnpackedParams
->lppos
;
279 RtlCopyMemory(UnpackedParams
, PackedParams
, sizeof(NCCALCSIZE_PARAMS
));
280 UnpackedParams
->lppos
= UnpackedWindowPos
;
281 RtlCopyMemory(UnpackedWindowPos
, PackedParams
+ 1, sizeof(WINDOWPOS
));
282 ExFreePool((PVOID
) lParamPacked
);
284 return STATUS_SUCCESS
;
286 else if (WM_CREATE
== Msg
|| WM_NCCREATE
== Msg
)
288 ExFreePool((PVOID
) lParamPacked
);
290 return STATUS_SUCCESS
;
295 return STATUS_INVALID_PARAMETER
;
302 ( PWINDOW_OBJECT Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
304 BOOL SameThread
= FALSE
;
306 if (Window
->ti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread())->ThreadInfo
)
309 if ((!SameThread
&& (Window
->ti
->fsHooks
& HOOKID_TO_FLAG(WH_CALLWNDPROC
))) ||
310 (SameThread
&& ISITHOOKED(WH_CALLWNDPROC
)) )
317 co_HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, SameThread
, (LPARAM
)&CWP
);
324 ( PWINDOW_OBJECT Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*uResult
)
326 BOOL SameThread
= FALSE
;
328 if (Window
->ti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread())->ThreadInfo
)
331 if ((!SameThread
&& (Window
->ti
->fsHooks
& HOOKID_TO_FLAG(WH_CALLWNDPROCRET
))) ||
332 (SameThread
&& ISITHOOKED(WH_CALLWNDPROCRET
)) )
337 CWPR
.wParam
= wParam
;
338 CWPR
.lParam
= lParam
;
339 CWPR
.lResult
= *uResult
;
340 co_HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, SameThread
, (LPARAM
)&CWPR
);
346 IntDispatchMessage(PMSG pMsg
)
348 LARGE_INTEGER TickCount
;
351 PWINDOW_OBJECT Window
= NULL
;
355 Window
= UserGetWindowObject(pMsg
->hwnd
);
356 if (!Window
|| !Window
->Wnd
) return 0;
359 if (((pMsg
->message
== WM_SYSTIMER
) ||
360 (pMsg
->message
== WM_TIMER
)) &&
363 if (pMsg
->message
== WM_TIMER
)
365 if (ValidateTimerCallback(PsGetCurrentThreadWin32Thread(),Window
,pMsg
->wParam
,pMsg
->lParam
))
367 KeQueryTickCount(&TickCount
);
368 Time
= MsqCalculateMessageTime(&TickCount
);
369 return co_IntCallWindowProc((WNDPROC
)pMsg
->lParam
,
381 PTIMER pTimer
= FindSystemTimer(pMsg
);
382 if (pTimer
&& pTimer
->pfn
)
384 KeQueryTickCount(&TickCount
);
385 Time
= MsqCalculateMessageTime(&TickCount
);
386 pTimer
->pfn(pMsg
->hwnd
, WM_SYSTIMER
, (UINT
)pMsg
->wParam
, Time
);
392 if (!Window
) return 0;
394 retval
= co_IntPostOrSendMessage(pMsg
->hwnd
, pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
396 if (pMsg
->message
== WM_PAINT
)
398 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
399 HRGN hrgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
400 co_UserGetUpdateRgn( Window
, hrgn
, TRUE
);
401 GreDeleteObject( hrgn
);
413 BOOL BadChk
= FALSE
, Ret
= TRUE
;
415 DECLARE_RETURN(BOOL
);
417 DPRINT("Enter NtUserCallMsgFilter\n");
418 UserEnterExclusive();
423 ProbeForRead((PVOID
)lpmsg
,
430 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
439 if (BadChk
) RETURN( FALSE
);
441 if (!co_HOOK_CallHooks( WH_SYSMSGFILTER
, code
, 0, (LPARAM
)&Msg
))
443 Ret
= co_HOOK_CallHooks( WH_MSGFILTER
, code
, 0, (LPARAM
)&Msg
);
448 ProbeForWrite((PVOID
)lpmsg
,
451 RtlCopyMemory((PVOID
)lpmsg
,
455 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
460 if (BadChk
) RETURN( FALSE
);
464 DPRINT("Leave NtUserCallMsgFilter. ret=%i\n", _ret_
);
470 NtUserDispatchMessage(PMSG UnsafeMsgInfo
)
476 UserEnterExclusive();
479 ProbeForRead(UnsafeMsgInfo
, sizeof(MSG
), 1);
480 RtlCopyMemory(&SafeMsg
, UnsafeMsgInfo
, sizeof(MSG
));
482 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
484 SetLastNtError(_SEH2_GetExceptionCode());
489 if (!Hit
) Res
= IntDispatchMessage(&SafeMsg
);
497 NtUserTranslateMessage(LPMSG lpMsg
,
502 DECLARE_RETURN(BOOL
);
504 DPRINT("Enter NtUserTranslateMessage\n");
505 UserEnterExclusive();
507 Status
= MmCopyFromCaller(&SafeMsg
, lpMsg
, sizeof(MSG
));
508 if(!NT_SUCCESS(Status
))
510 SetLastNtError(Status
);
514 RETURN( IntTranslateKbdMessage(&SafeMsg
, dwhkl
));
517 DPRINT("Leave NtUserTranslateMessage: ret=%i\n",_ret_
);
524 co_IntSendHitTestMessages(PUSER_MESSAGE_QUEUE ThreadQueue
, LPMSG Msg
)
526 if(!Msg
->hwnd
|| ThreadQueue
->CaptureWindow
)
535 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
540 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
547 case WM_LBUTTONDBLCLK
:
548 case WM_MBUTTONDBLCLK
:
549 case WM_RBUTTONDBLCLK
:
550 case WM_XBUTTONDBLCLK
:
553 PSYSTEM_CURSORINFO CurInfo
;
555 if(!IntGetWindowStationObject(InputWindowStation
))
559 CurInfo
= IntGetSysCursorInfo(InputWindowStation
);
560 wParam
= (WPARAM
)(CurInfo
->ButtonsDown
);
561 ObDereferenceObject(InputWindowStation
);
563 co_IntSendMessage(Msg
->hwnd
, WM_MOUSEMOVE
, wParam
, Msg
->lParam
);
564 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
567 case WM_NCLBUTTONDOWN
:
568 case WM_NCMBUTTONDOWN
:
569 case WM_NCRBUTTONDOWN
:
570 case WM_NCXBUTTONDOWN
:
571 case WM_NCLBUTTONDBLCLK
:
572 case WM_NCMBUTTONDBLCLK
:
573 case WM_NCRBUTTONDBLCLK
:
574 case WM_NCXBUTTONDBLCLK
:
576 co_IntSendMessage(Msg
->hwnd
, WM_NCMOUSEMOVE
, (WPARAM
)Msg
->wParam
, Msg
->lParam
);
577 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
584 co_IntActivateWindowMouse(PUSER_MESSAGE_QUEUE ThreadQueue
, LPMSG Msg
, PWINDOW_OBJECT MsgWindow
,
588 PWINDOW_OBJECT Parent
;
590 ASSERT_REFS_CO(MsgWindow
);
592 if(*HitTest
== (USHORT
)HTTRANSPARENT
)
594 /* eat the message, search again! */
598 Parent
= IntGetParent(MsgWindow
);//fixme: deref retval?
600 /* If no parent window, pass MsgWindows HWND as wParam. Fixes bug #3111 */
601 Result
= co_IntSendMessage(MsgWindow
->hSelf
,
603 (WPARAM
) (Parent
? Parent
->hSelf
: MsgWindow
->hSelf
),
604 (LPARAM
)MAKELONG(*HitTest
, Msg
->message
)
609 case MA_NOACTIVATEANDEAT
:
613 case MA_ACTIVATEANDEAT
:
614 co_IntMouseActivateWindow(MsgWindow
);
618 co_IntMouseActivateWindow(MsgWindow
);
626 co_IntTranslateMouseMessage(PUSER_MESSAGE_QUEUE ThreadQueue
, LPMSG Msg
, USHORT
*HitTest
, BOOL Remove
)
628 PWINDOW_OBJECT Window
;
629 USER_REFERENCE_ENTRY Ref
, DesktopRef
;
631 if(!(Window
= UserGetWindowObject(Msg
->hwnd
)))
633 /* let's just eat the message?! */
637 UserRefObjectCo(Window
, &Ref
);
639 if(ThreadQueue
== Window
->MessageQueue
&&
640 ThreadQueue
->CaptureWindow
!= Window
->hSelf
)
642 /* only send WM_NCHITTEST messages if we're not capturing the window! */
643 *HitTest
= co_IntSendMessage(Window
->hSelf
, WM_NCHITTEST
, 0,
644 MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
));
646 if(*HitTest
== (USHORT
)HTTRANSPARENT
)
648 PWINDOW_OBJECT DesktopWindow
;
649 HWND hDesktop
= IntGetDesktopWindow();
651 if((DesktopWindow
= UserGetWindowObject(hDesktop
)))
655 UserRefObjectCo(DesktopWindow
, &DesktopRef
);
657 co_WinPosWindowFromPoint(DesktopWindow
, Window
->MessageQueue
, &Msg
->pt
, &Wnd
);
662 /* post the message to the other window */
663 Msg
->hwnd
= Wnd
->hSelf
;
664 if(!(Wnd
->Status
& WINDOWSTATUS_DESTROYING
))
666 MsqPostMessage(Wnd
->MessageQueue
, Msg
, FALSE
,
667 Msg
->message
== WM_MOUSEMOVE
? QS_MOUSEMOVE
:
671 /* eat the message */
672 UserDereferenceObject(Wnd
);
673 UserDerefObjectCo(DesktopWindow
);
674 UserDerefObjectCo(Window
);
677 UserDereferenceObject(Wnd
);
680 UserDerefObjectCo(DesktopWindow
);
689 if(IS_BTN_MESSAGE(Msg
->message
, DOWN
))
691 /* generate double click messages, if necessary */
692 if ((((*HitTest
) != HTCLIENT
) ||
693 (Window
->Wnd
->Class
->Style
& CS_DBLCLKS
)) &&
694 MsqIsDblClk(Msg
, Remove
))
696 Msg
->message
+= WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
;
700 if(Msg
->message
!= WM_MOUSEWHEEL
)
703 if ((*HitTest
) != HTCLIENT
)
705 Msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
706 if((Msg
->message
== WM_NCRBUTTONUP
) &&
707 (((*HitTest
) == HTCAPTION
) || ((*HitTest
) == HTSYSMENU
)))
709 Msg
->message
= WM_CONTEXTMENU
;
710 Msg
->wParam
= (WPARAM
)Window
->hSelf
;
714 Msg
->wParam
= *HitTest
;
716 Msg
->lParam
= MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
);
718 else if(ThreadQueue
->MoveSize
== NULL
&&
719 ThreadQueue
->MenuOwner
== NULL
)
721 /* NOTE: Msg->pt should remain in screen coordinates. -- FiN */
722 Msg
->lParam
= MAKELONG(
723 Msg
->pt
.x
- (WORD
)Window
->Wnd
->ClientRect
.left
,
724 Msg
->pt
.y
- (WORD
)Window
->Wnd
->ClientRect
.top
);
728 UserDerefObjectCo(Window
);
734 * Internal version of PeekMessage() doing all the work
737 co_IntPeekMessage(PUSER_MESSAGE Msg
,
744 LARGE_INTEGER LargeTickCount
;
745 PUSER_MESSAGE_QUEUE ThreadQueue
;
746 PUSER_MESSAGE Message
;
747 BOOL Present
, RemoveMessages
;
748 USER_REFERENCE_ENTRY Ref
;
750 MOUSEHOOKSTRUCT MHook
;
752 /* The queues and order in which they are checked are documented in the MSDN
753 article on GetMessage() */
755 pti
= PsGetCurrentThreadWin32Thread();
756 ThreadQueue
= pti
->MessageQueue
;
758 /* Inspect RemoveMsg flags */
759 /* FIXME: The only flag we process is PM_REMOVE - processing of others must still be implemented */
760 RemoveMessages
= RemoveMsg
& PM_REMOVE
;
766 KeQueryTickCount(&LargeTickCount
);
767 ThreadQueue
->LastMsgRead
= LargeTickCount
.u
.LowPart
;
769 /* Dispatch sent messages here. */
770 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
773 /* Now look for a quit message. */
775 if (ThreadQueue
->QuitPosted
)
777 /* According to the PSDK, WM_QUIT messages are always returned, regardless
778 of the filter specified */
779 Msg
->Msg
.hwnd
= NULL
;
780 Msg
->Msg
.message
= WM_QUIT
;
781 Msg
->Msg
.wParam
= ThreadQueue
->QuitExitCode
;
783 Msg
->FreeLParam
= FALSE
;
786 ThreadQueue
->QuitPosted
= FALSE
;
791 /* Now check for normal messages. */
792 Present
= co_MsqFindMessage(ThreadQueue
,
801 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
804 MsqDestroyMessage(Message
);
809 /* Check for hardware events. */
810 Present
= co_MsqFindMessage(ThreadQueue
,
819 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
822 MsqDestroyMessage(Message
);
827 /* Check for sent messages again. */
828 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
831 /* Check for paint messages. */
832 if (IntGetPaintMessage(hWnd
, MsgFilterMin
, MsgFilterMax
, pti
, &Msg
->Msg
, RemoveMessages
))
834 Msg
->FreeLParam
= FALSE
;
838 if (ThreadQueue
->WakeMask
& QS_TIMER
)
839 if (PostTimerMessages(hWnd
)) // If there are timers ready,
840 goto CheckMessages
; // go back and process them.
842 // LOL! Polling Timer Queue? How much time is spent doing this?
843 /* Check for WM_(SYS)TIMER messages */
844 Present
= MsqGetTimerMessage(ThreadQueue
, hWnd
, MsgFilterMin
, MsgFilterMax
,
845 &Msg
->Msg
, RemoveMessages
);
848 Msg
->FreeLParam
= FALSE
;
858 PWINDOW_OBJECT MsgWindow
= NULL
;
860 if(Msg
->Msg
.hwnd
&& (MsgWindow
= UserGetWindowObject(Msg
->Msg
.hwnd
)) &&
861 Msg
->Msg
.message
>= WM_MOUSEFIRST
&& Msg
->Msg
.message
<= WM_MOUSELAST
)
865 UserRefObjectCo(MsgWindow
, &Ref
);
867 if(co_IntTranslateMouseMessage(ThreadQueue
, &Msg
->Msg
, &HitTest
, TRUE
))
868 /* FIXME - check message filter again, if the message doesn't match anymore,
871 UserDerefObjectCo(MsgWindow
);
872 /* eat the message, search again */
876 if(ThreadQueue
->CaptureWindow
== NULL
)
878 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
879 if((Msg
->Msg
.message
!= WM_MOUSEMOVE
&& Msg
->Msg
.message
!= WM_NCMOUSEMOVE
) &&
880 IS_BTN_MESSAGE(Msg
->Msg
.message
, DOWN
) &&
881 co_IntActivateWindowMouse(ThreadQueue
, &Msg
->Msg
, MsgWindow
, &HitTest
))
883 UserDerefObjectCo(MsgWindow
);
884 /* eat the message, search again */
889 UserDerefObjectCo(MsgWindow
);
893 co_IntSendHitTestMessages(ThreadQueue
, &Msg
->Msg
);
898 // UserDereferenceObject(MsgWindow);
904 if((Msg
->Msg
.hwnd
&& Msg
->Msg
.message
>= WM_MOUSEFIRST
&& Msg
->Msg
.message
<= WM_MOUSELAST
) &&
905 co_IntTranslateMouseMessage(ThreadQueue
, &Msg
->Msg
, &HitTest
, FALSE
))
906 /* FIXME - check message filter again, if the message doesn't match anymore,
909 /* eat the message, search again */
913 if ( ISITHOOKED(WH_MOUSE
) &&
914 Msg
->Msg
.message
>= WM_MOUSEFIRST
&&
915 Msg
->Msg
.message
<= WM_MOUSELAST
)
917 MHook
.pt
= Msg
->Msg
.pt
;
918 MHook
.hwnd
= Msg
->Msg
.hwnd
;
919 MHook
.wHitTestCode
= HitTest
;
920 MHook
.dwExtraInfo
= 0;
921 if (co_HOOK_CallHooks( WH_MOUSE
,
922 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
926 if (ISITHOOKED(WH_CBT
))
928 MHook
.pt
= Msg
->Msg
.pt
;
929 MHook
.hwnd
= Msg
->Msg
.hwnd
;
930 MHook
.wHitTestCode
= HitTest
;
931 MHook
.dwExtraInfo
= 0;
932 co_HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
,
933 Msg
->Msg
.message
, (LPARAM
)&MHook
);
938 if ( ISITHOOKED(WH_KEYBOARD
) &&
939 (Msg
->Msg
.message
== WM_KEYDOWN
|| Msg
->Msg
.message
== WM_KEYUP
) )
941 if (co_HOOK_CallHooks( WH_KEYBOARD
,
942 RemoveMsg
? HC_ACTION
: HC_NOREMOVE
,
943 LOWORD(Msg
->Msg
.wParam
),
946 if (ISITHOOKED(WH_CBT
))
948 /* skip this message */
949 co_HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
,
950 LOWORD(Msg
->Msg
.wParam
), Msg
->Msg
.lParam
);
955 // The WH_GETMESSAGE hook enables an application to monitor messages about to
956 // be returned by the GetMessage or PeekMessage function.
957 if (ISITHOOKED(WH_GETMESSAGE
))
959 //DPRINT1("Peek WH_GETMESSAGE -> %x\n",&Msg);
960 co_HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, RemoveMsg
& PM_REMOVE
, (LPARAM
)&Msg
->Msg
);
969 NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
977 NTUSERGETMESSAGEINFO Info
;
978 PWINDOW_OBJECT Window
;
979 PMSGMEMORY MsgMemoryEntry
;
983 DECLARE_RETURN(BOOL
);
985 DPRINT("Enter NtUserPeekMessage\n");
986 UserEnterExclusive();
989 if (hWnd
&& hWnd
!= INVALID_HANDLE_VALUE
)
991 if (!(Window
= UserGetWindowObject(hWnd
)))
997 if (MsgFilterMax
< MsgFilterMin
)
1003 Present
= co_IntPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
);
1008 /* See if this message type is present in the table */
1009 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
1010 if (NULL
== MsgMemoryEntry
)
1012 /* Not present, no copying needed */
1013 Info
.LParamSize
= 0;
1017 /* Determine required size */
1018 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
1020 /* Allocate required amount of user-mode memory */
1021 Info
.LParamSize
= Size
;
1023 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
1024 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
1025 if (! NT_SUCCESS(Status
))
1027 SetLastNtError(Status
);
1030 /* Transfer lParam data to user-mode mem */
1031 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
1032 if (! NT_SUCCESS(Status
))
1034 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
1035 &Info
.LParamSize
, MEM_RELEASE
);
1036 SetLastNtError(Status
);
1039 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
1041 if (RemoveMsg
&& Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
1043 ExFreePool((void *) Msg
.Msg
.lParam
);
1045 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
1046 if (! NT_SUCCESS(Status
))
1048 SetLastNtError(Status
);
1056 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
1061 static BOOL FASTCALL
1062 co_IntWaitMessage(HWND Wnd
,
1067 PUSER_MESSAGE_QUEUE ThreadQueue
;
1071 pti
= PsGetCurrentThreadWin32Thread();
1072 ThreadQueue
= pti
->MessageQueue
;
1076 if (co_IntPeekMessage(&Msg
, Wnd
, MsgFilterMin
, MsgFilterMax
, PM_NOREMOVE
))
1081 /* Nothing found. Wait for new messages. */
1082 Status
= co_MsqWaitForNewMessages(ThreadQueue
, Wnd
, MsgFilterMin
, MsgFilterMax
);
1084 while ((STATUS_WAIT_0
<= Status
&& Status
<= STATUS_WAIT_63
) || STATUS_TIMEOUT
== Status
);
1086 SetLastNtError(Status
);
1092 NtUserGetMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
1097 * FUNCTION: Get a message from the calling thread's message queue.
1099 * UnsafeMsg - Pointer to the structure which receives the returned message.
1100 * Wnd - Window whose messages are to be retrieved.
1101 * MsgFilterMin - Integer value of the lowest message value to be
1103 * MsgFilterMax - Integer value of the highest message value to be
1108 NTUSERGETMESSAGEINFO Info
;
1110 /* FIXME: if initialization is removed, gcc complains that this may be used before initialization. Please review */
1111 PWINDOW_OBJECT Window
= NULL
;
1112 PMSGMEMORY MsgMemoryEntry
;
1116 DECLARE_RETURN(BOOL
);
1117 // USER_REFERENCE_ENTRY Ref;
1119 DPRINT("Enter NtUserGetMessage\n");
1120 UserEnterExclusive();
1122 /* Validate input */
1123 if (hWnd
&& !(Window
= UserGetWindowObject(hWnd
)))
1128 // if (Window) UserRefObjectCo(Window, &Ref);
1130 if (MsgFilterMax
< MsgFilterMin
)
1138 GotMessage
= co_IntPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
);
1142 /* See if this message type is present in the table */
1143 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
1144 if (NULL
== MsgMemoryEntry
)
1146 /* Not present, no copying needed */
1147 Info
.LParamSize
= 0;
1151 /* Determine required size */
1152 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
1154 /* Allocate required amount of user-mode memory */
1155 Info
.LParamSize
= Size
;
1157 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
1158 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
1160 if (! NT_SUCCESS(Status
))
1162 SetLastNtError(Status
);
1165 /* Transfer lParam data to user-mode mem */
1166 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
1167 if (! NT_SUCCESS(Status
))
1169 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
1170 &Info
.LParamSize
, MEM_DECOMMIT
);
1171 SetLastNtError(Status
);
1174 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
1176 if (Msg
.FreeLParam
&& 0 != Msg
.Msg
.lParam
)
1178 ExFreePool((void *) Msg
.Msg
.lParam
);
1180 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
1181 if (! NT_SUCCESS(Status
))
1183 SetLastNtError(Status
);
1187 else if (! co_IntWaitMessage(hWnd
, MsgFilterMin
, MsgFilterMax
))
1192 while (! GotMessage
);
1194 RETURN( WM_QUIT
!= Info
.Msg
.message
);
1197 // if (Window) UserDerefObjectCo(Window);
1199 DPRINT("Leave NtUserGetMessage\n");
1205 static NTSTATUS FASTCALL
1206 CopyMsgToKernelMem(MSG
*KernelModeMsg
, MSG
*UserModeMsg
, PMSGMEMORY MsgMemoryEntry
)
1213 *KernelModeMsg
= *UserModeMsg
;
1215 /* See if this message type is present in the table */
1216 if (NULL
== MsgMemoryEntry
)
1218 /* Not present, no copying needed */
1219 return STATUS_SUCCESS
;
1222 /* Determine required size */
1223 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
1227 /* Allocate kernel mem */
1228 KernelMem
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
1229 if (NULL
== KernelMem
)
1231 DPRINT1("Not enough memory to copy message to kernel mem\n");
1232 return STATUS_NO_MEMORY
;
1234 KernelModeMsg
->lParam
= (LPARAM
) KernelMem
;
1236 /* Copy data if required */
1237 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_READ
))
1239 Status
= MmCopyFromCaller(KernelMem
, (PVOID
) UserModeMsg
->lParam
, Size
);
1240 if (! NT_SUCCESS(Status
))
1242 DPRINT1("Failed to copy message to kernel: invalid usermode buffer\n");
1243 ExFreePoolWithTag(KernelMem
, TAG_MSG
);
1249 /* Make sure we don't pass any secrets to usermode */
1250 RtlZeroMemory(KernelMem
, Size
);
1255 KernelModeMsg
->lParam
= 0;
1258 return STATUS_SUCCESS
;
1261 static NTSTATUS FASTCALL
1262 CopyMsgToUserMem(MSG
*UserModeMsg
, MSG
*KernelModeMsg
)
1265 PMSGMEMORY MsgMemoryEntry
;
1268 /* See if this message type is present in the table */
1269 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
->message
);
1270 if (NULL
== MsgMemoryEntry
)
1272 /* Not present, no copying needed */
1273 return STATUS_SUCCESS
;
1276 /* Determine required size */
1277 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
1281 /* Copy data if required */
1282 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_WRITE
))
1284 Status
= MmCopyToCaller((PVOID
) UserModeMsg
->lParam
, (PVOID
) KernelModeMsg
->lParam
, Size
);
1285 if (! NT_SUCCESS(Status
))
1287 DPRINT1("Failed to copy message from kernel: invalid usermode buffer\n");
1288 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1293 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1296 return STATUS_SUCCESS
;
1300 UserPostMessage(HWND Wnd
,
1306 MSG UserModeMsg
, KernelModeMsg
;
1307 LARGE_INTEGER LargeTickCount
;
1309 PMSGMEMORY MsgMemoryEntry
;
1311 pti
= PsGetCurrentThreadWin32Thread();
1314 MsqPostQuitMessage(pti
->MessageQueue
, wParam
);
1316 else if (Wnd
== HWND_BROADCAST
)
1319 PWINDOW_OBJECT DesktopWindow
;
1322 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1323 List
= IntWinListChildren(DesktopWindow
);
1327 for (i
= 0; List
[i
]; i
++)
1328 UserPostMessage(List
[i
], Msg
, wParam
, lParam
);
1334 PWINDOW_OBJECT Window
;
1336 Window
= UserGetWindowObject(Wnd
);
1341 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
1343 DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd
);
1344 /* FIXME - last error code? */
1348 UserModeMsg
.hwnd
= Wnd
;
1349 UserModeMsg
.message
= Msg
;
1350 UserModeMsg
.wParam
= wParam
;
1351 UserModeMsg
.lParam
= lParam
;
1352 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1353 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1354 if (! NT_SUCCESS(Status
))
1356 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1359 IntGetCursorLocation(pti
->Desktop
->WindowStation
,
1361 KeQueryTickCount(&LargeTickCount
);
1362 pti
->timeLast
= KernelModeMsg
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1363 MsqPostMessage(Window
->MessageQueue
, &KernelModeMsg
,
1364 NULL
!= MsgMemoryEntry
&& 0 != KernelModeMsg
.lParam
,
1373 NtUserPostMessage(HWND hWnd
,
1378 DECLARE_RETURN(BOOL
);
1380 DPRINT("Enter NtUserPostMessage\n");
1381 UserEnterExclusive();
1383 RETURN(UserPostMessage(hWnd
, Msg
, wParam
, lParam
));
1386 DPRINT("Leave NtUserPostMessage, ret=%i\n",_ret_
);
1394 NtUserPostThreadMessage(DWORD idThread
,
1399 MSG UserModeMsg
, KernelModeMsg
;
1401 PTHREADINFO pThread
;
1403 PMSGMEMORY MsgMemoryEntry
;
1404 DECLARE_RETURN(BOOL
);
1406 DPRINT("Enter NtUserPostThreadMessage\n");
1407 UserEnterExclusive();
1409 Status
= PsLookupThreadByThreadId((HANDLE
)idThread
,&peThread
);
1411 if( Status
== STATUS_SUCCESS
)
1413 pThread
= (PTHREADINFO
)peThread
->Tcb
.Win32Thread
;
1414 if( !pThread
|| !pThread
->MessageQueue
)
1416 ObDereferenceObject( peThread
);
1420 UserModeMsg
.hwnd
= NULL
;
1421 UserModeMsg
.message
= Msg
;
1422 UserModeMsg
.wParam
= wParam
;
1423 UserModeMsg
.lParam
= lParam
;
1424 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1425 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1426 if (! NT_SUCCESS(Status
))
1428 ObDereferenceObject( peThread
);
1429 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1432 MsqPostMessage(pThread
->MessageQueue
, &KernelModeMsg
,
1433 NULL
!= MsgMemoryEntry
&& 0 != KernelModeMsg
.lParam
,
1435 ObDereferenceObject( peThread
);
1440 SetLastNtError( Status
);
1445 DPRINT("Leave NtUserPostThreadMessage, ret=%i\n",_ret_
);
1451 NtUserQuerySendMessage(DWORD Unknown0
)
1459 co_IntSendMessage(HWND hWnd
,
1464 ULONG_PTR Result
= 0;
1465 if(co_IntSendMessageTimeout(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
))
1467 return (LRESULT
)Result
;
1474 co_IntSendMessageTimeoutSingle(HWND hWnd
,
1484 PWINDOW_OBJECT Window
= NULL
;
1485 PMSGMEMORY MsgMemoryEntry
;
1486 INT lParamBufferSize
;
1487 LPARAM lParamPacked
;
1488 PTHREADINFO Win32Thread
;
1489 DECLARE_RETURN(LRESULT
);
1490 USER_REFERENCE_ENTRY Ref
;
1492 if (!(Window
= UserGetWindowObject(hWnd
)))
1497 UserRefObjectCo(Window
, &Ref
);
1499 Win32Thread
= PsGetCurrentThreadWin32Thread();
1501 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1503 if (NULL
!= Win32Thread
&&
1504 Window
->MessageQueue
== Win32Thread
->MessageQueue
)
1506 if (Win32Thread
->IsExiting
)
1508 /* Never send messages to exiting threads */
1512 /* See if this message type is present in the table */
1513 MsgMemoryEntry
= FindMsgMemory(Msg
);
1514 if (NULL
== MsgMemoryEntry
)
1516 lParamBufferSize
= -1;
1520 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1523 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
)))
1525 DPRINT1("Failed to pack message parameters\n");
1529 Result
= (ULONG_PTR
)co_IntCallWindowProc(Window
->Wnd
->WndProc
, !Window
->Wnd
->Unicode
, hWnd
, Msg
, wParam
,
1530 lParamPacked
,lParamBufferSize
);
1537 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1539 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
)))
1541 DPRINT1("Failed to unpack message parameters\n");
1548 if (uFlags
& SMTO_ABORTIFHUNG
&& MsqIsHung(Window
->MessageQueue
))
1550 /* FIXME - Set a LastError? */
1554 if (Window
->Status
& WINDOWSTATUS_DESTROYING
)
1556 /* FIXME - last error? */
1557 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1563 Status
= co_MsqSendMessage( Window
->MessageQueue
,
1569 (uFlags
& SMTO_BLOCK
),
1573 while ((STATUS_TIMEOUT
== Status
) &&
1574 (uFlags
& SMTO_NOTIMEOUTIFNOTHUNG
) &&
1575 !MsqIsHung(Window
->MessageQueue
));
1577 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1579 if (STATUS_TIMEOUT
== Status
)
1583 Microsoft Windows 2000: If GetLastError returns zero, then the function
1585 XP+ : If the function fails or times out, the return value is zero.
1586 To get extended error information, call GetLastError. If GetLastError
1587 returns ERROR_TIMEOUT, then the function timed out.
1589 SetLastWin32Error(ERROR_TIMEOUT
);
1592 else if (! NT_SUCCESS(Status
))
1594 SetLastNtError(Status
);
1601 if (Window
) UserDerefObjectCo(Window
);
1606 co_IntSendMessageTimeout(HWND hWnd
,
1614 PWINDOW_OBJECT DesktopWindow
;
1618 if (HWND_BROADCAST
!= hWnd
)
1620 return co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1623 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1624 if (NULL
== DesktopWindow
)
1626 SetLastWin32Error(ERROR_INTERNAL_ERROR
);
1630 Children
= IntWinListChildren(DesktopWindow
);
1631 if (NULL
== Children
)
1636 for (Child
= Children
; NULL
!= *Child
; Child
++)
1638 co_IntSendMessageTimeoutSingle(*Child
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1641 ExFreePool(Children
);
1643 return (LRESULT
) TRUE
;
1647 /* This function posts a message if the destination's message queue belongs to
1648 another thread, otherwise it sends the message. It does not support broadcast
1651 co_IntPostOrSendMessage(HWND hWnd
,
1658 PWINDOW_OBJECT Window
;
1660 if(hWnd
== HWND_BROADCAST
)
1665 if(!(Window
= UserGetWindowObject(hWnd
)))
1670 pti
= PsGetCurrentThreadWin32Thread();
1671 if(Window
->MessageQueue
!= pti
->MessageQueue
)
1673 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1677 if(!co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
)) {
1682 return (LRESULT
)Result
;
1686 co_IntDoSendMessage(HWND hWnd
,
1691 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1694 LRESULT Result
= TRUE
;
1696 PWINDOW_OBJECT Window
= NULL
;
1697 NTUSERSENDMESSAGEINFO Info
;
1700 PMSGMEMORY MsgMemoryEntry
;
1702 RtlZeroMemory(&Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1704 /* FIXME: Call hooks. */
1705 if (HWND_BROADCAST
!= hWnd
)
1707 Window
= UserGetWindowObject(hWnd
);
1710 /* Tell usermode to not touch this one */
1711 Info
.HandledByKernel
= TRUE
;
1712 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1719 /* FIXME: Check for an exiting window. */
1721 /* See if the current thread can handle the message */
1722 pti
= PsGetCurrentThreadWin32Thread();
1723 if (HWND_BROADCAST
!= hWnd
&& NULL
!= pti
&&
1724 Window
->MessageQueue
== pti
->MessageQueue
)
1726 /* Gather the information usermode needs to call the window proc directly */
1727 Info
.HandledByKernel
= FALSE
;
1729 Status
= MmCopyFromCaller(&(Info
.Ansi
), &(UnsafeInfo
->Ansi
),
1731 if (! NT_SUCCESS(Status
))
1733 Info
.Ansi
= ! Window
->Wnd
->Unicode
;
1736 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1738 if (Window
->Wnd
->IsSystem
)
1740 Info
.Proc
= (!Info
.Ansi
? Window
->Wnd
->WndProc
: Window
->Wnd
->WndProcExtra
);
1744 Info
.Ansi
= !Window
->Wnd
->Unicode
;
1745 Info
.Proc
= Window
->Wnd
->WndProc
;
1748 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, &Result
);
1753 /* Must be handled by other thread */
1754 // if (HWND_BROADCAST != hWnd)
1756 // UserDereferenceObject(Window);
1758 Info
.HandledByKernel
= TRUE
;
1759 UserModeMsg
.hwnd
= hWnd
;
1760 UserModeMsg
.message
= Msg
;
1761 UserModeMsg
.wParam
= wParam
;
1762 UserModeMsg
.lParam
= lParam
;
1763 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1764 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1765 if (! NT_SUCCESS(Status
))
1767 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1768 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1769 return (dsm
? 0 : -1);
1773 Result
= co_IntSendMessage(KernelModeMsg
.hwnd
, KernelModeMsg
.message
,
1774 KernelModeMsg
.wParam
, KernelModeMsg
.lParam
);
1778 Result
= co_IntSendMessageTimeout(KernelModeMsg
.hwnd
, KernelModeMsg
.message
,
1779 KernelModeMsg
.wParam
, KernelModeMsg
.lParam
,
1780 dsm
->uFlags
, dsm
->uTimeout
, &dsm
->Result
);
1782 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1783 if (! NT_SUCCESS(Status
))
1785 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1786 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1787 return(dsm
? 0 : -1);
1791 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1792 if (! NT_SUCCESS(Status
))
1794 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1797 return (LRESULT
)Result
;
1801 NtUserSendMessageTimeout(HWND hWnd
,
1808 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1812 DECLARE_RETURN(BOOL
);
1814 DPRINT("Enter NtUserSendMessageTimeout\n");
1815 UserEnterExclusive();
1817 dsm
.uFlags
= uFlags
;
1818 dsm
.uTimeout
= uTimeout
;
1819 Result
= co_IntDoSendMessage(hWnd
, Msg
, wParam
, lParam
, &dsm
, UnsafeInfo
);
1820 if(uResult
!= NULL
&& Result
!= 0)
1824 Status
= MmCopyToCaller(uResult
, &dsm
.Result
, sizeof(ULONG_PTR
));
1825 if(!NT_SUCCESS(Status
))
1827 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1834 DPRINT("Leave NtUserSendMessageTimeout, ret=%i\n",_ret_
);
1840 NtUserSendMessage(HWND Wnd
,
1844 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1846 DECLARE_RETURN(BOOL
);
1848 DPRINT("Enter NtUserSendMessage\n");
1849 UserEnterExclusive();
1851 RETURN(co_IntDoSendMessage(Wnd
, Msg
, wParam
, lParam
, NULL
, UnsafeInfo
));
1854 DPRINT("Leave NtUserSendMessage, ret=%i\n",_ret_
);
1861 UserSendNotifyMessage(HWND hWnd
,
1867 // Basicly the same as IntPostOrSendMessage
1868 if (hWnd
== HWND_BROADCAST
) //Handle Broadcast
1871 PWINDOW_OBJECT DesktopWindow
;
1874 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1875 List
= IntWinListChildren(DesktopWindow
);
1879 for (i
= 0; List
[i
]; i
++)
1881 UserSendNotifyMessage(List
[i
], Msg
, wParam
, lParam
);
1890 PWINDOW_OBJECT Window
;
1894 PMSGMEMORY MsgMemoryEntry
;
1896 if(!(Window
= UserGetWindowObject(hWnd
))) return FALSE
;
1898 pti
= PsGetCurrentThreadWin32Thread();
1899 if(Window
->MessageQueue
!= pti
->MessageQueue
)
1900 { // Send message w/o waiting for it.
1901 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1904 { // Handle message and callback.
1905 UserModeMsg
.hwnd
= hWnd
;
1906 UserModeMsg
.message
= Msg
;
1907 UserModeMsg
.wParam
= wParam
;
1908 UserModeMsg
.lParam
= lParam
;
1909 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1910 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1911 if (! NT_SUCCESS(Status
))
1913 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1916 Result
= co_IntSendMessageTimeoutSingle(
1917 KernelModeMsg
.hwnd
, KernelModeMsg
.message
,
1918 KernelModeMsg
.wParam
, KernelModeMsg
.lParam
,
1919 SMTO_NORMAL
, 0, &PResult
);
1921 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1922 if (! NT_SUCCESS(Status
))
1924 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1934 NtUserSendNotifyMessage(HWND hWnd
,
1939 DECLARE_RETURN(BOOL
);
1941 DPRINT("EnterNtUserSendNotifyMessage\n");
1942 UserEnterExclusive();
1944 RETURN(UserSendNotifyMessage(hWnd
, Msg
, wParam
, lParam
));
1947 DPRINT("Leave NtUserSendNotifyMessage, ret=%i\n",_ret_
);
1955 NtUserWaitMessage(VOID
)
1957 DECLARE_RETURN(BOOL
);
1959 DPRINT("EnterNtUserWaitMessage\n");
1960 UserEnterExclusive();
1962 RETURN(co_IntWaitMessage(NULL
, 0, 0));
1965 DPRINT("Leave NtUserWaitMessage, ret=%i\n",_ret_
);
1971 IntGetQueueStatus(BOOL ClearChanges
)
1974 PUSER_MESSAGE_QUEUE Queue
;
1976 DECLARE_RETURN(DWORD
);
1978 DPRINT("Enter IntGetQueueStatus\n");
1980 pti
= PsGetCurrentThreadWin32Thread();
1981 Queue
= pti
->MessageQueue
;
1983 Result
= MAKELONG(Queue
->QueueBits
, Queue
->ChangedBits
);
1986 Queue
->ChangedBits
= 0;
1992 DPRINT("Leave IntGetQueueStatus, ret=%i\n",_ret_
);
1997 IntInitMessagePumpHook()
1999 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->ThreadInfo
)
2001 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->ThreadInfo
->ClientThreadInfo
.dwcPumpHook
++;
2008 IntUninitMessagePumpHook()
2010 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->ThreadInfo
)
2012 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->ThreadInfo
->ClientThreadInfo
.dwcPumpHook
<= 0)
2016 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->ThreadInfo
->ClientThreadInfo
.dwcPumpHook
--;
2029 ULONG_PTR ResultInfo
,
2030 DWORD dwType
, // fnID?
2033 LRESULT lResult
= 0;
2034 PWINDOW_OBJECT Window
= NULL
;
2035 USER_REFERENCE_ENTRY Ref
;
2037 UserEnterExclusive();
2039 /* Validate input */
2040 if (hWnd
&& (hWnd
!= INVALID_HANDLE_VALUE
) && !(Window
= UserGetWindowObject(hWnd
)))
2046 case FNID_DEFWINDOWPROC
:
2047 UserRefObjectCo(Window
, &Ref
);
2048 lResult
= IntDefWindowProc(Window
, Msg
, wParam
, lParam
, Ansi
);
2049 UserDerefObjectCo(Window
);
2051 case FNID_BROADCASTSYSTEMMESSAGE
:
2053 PBROADCASTPARM parm
;
2054 BOOL BadChk
= FALSE
;
2055 DWORD_PTR RetVal
= 0;
2062 ProbeForWrite((PVOID
)ResultInfo
,
2063 sizeof(BROADCASTPARM
),
2065 parm
= (PBROADCASTPARM
)ResultInfo
;
2067 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2077 if ( parm
->recipients
& BSM_ALLDESKTOPS
||
2078 parm
->recipients
== BSM_ALLCOMPONENTS
)
2081 else if (parm
->recipients
& BSM_APPLICATIONS
)
2083 if (parm
->flags
& BSF_QUERY
)
2085 if (parm
->flags
& BSF_FORCEIFHUNG
|| parm
->flags
& BSF_NOHANG
)
2087 co_IntSendMessageTimeout( HWND_BROADCAST
,
2095 else if (parm
->flags
& BSF_NOTIMEOUTIFNOTHUNG
)
2097 co_IntSendMessageTimeout( HWND_BROADCAST
,
2101 SMTO_NOTIMEOUTIFNOTHUNG
,
2107 co_IntSendMessageTimeout( HWND_BROADCAST
,
2116 else if (parm
->flags
& BSF_POSTMESSAGE
)
2118 lResult
= UserPostMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2120 else if ( parm
->flags
& BSF_SENDNOTIFYMESSAGE
)
2122 lResult
= UserSendNotifyMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2127 case FNID_SENDMESSAGECALLBACK
:
2129 // CallNextHook bypass.
2130 case FNID_CALLWNDPROC
:
2131 case FNID_CALLWNDPROCRET
:
2133 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
2134 PHOOK NextObj
, Hook
= ClientInfo
->phkCurrent
;
2136 if (!ClientInfo
|| !Hook
) break;
2138 UserReferenceObject(Hook
);
2140 if (Hook
->Thread
&& (Hook
->Thread
!= PsGetCurrentThread()))
2142 UserDereferenceObject(Hook
);
2146 NextObj
= IntGetNextHook(Hook
);
2147 ClientInfo
->phkCurrent
= NextObj
;
2149 if ( Hook
->HookId
== WH_CALLWNDPROC
)
2154 CWP
.wParam
= wParam
;
2155 CWP
.lParam
= lParam
;
2156 DPRINT("WH_CALLWNDPROC: Hook %x NextHook %x\n", Hook
, NextObj
);
2158 lResult
= co_IntCallHookProc( Hook
->HookId
,
2160 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2171 CWPR
.wParam
= wParam
;
2172 CWPR
.lParam
= lParam
;
2173 CWPR
.lResult
= ClientInfo
->dwHookData
;
2175 lResult
= co_IntCallHookProc( Hook
->HookId
,
2177 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2183 UserDereferenceObject(Hook
);
2184 lResult
= (LRESULT
) NextObj
;
2192 #define INFINITE 0xFFFFFFFF
2193 #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
2197 NtUserWaitForInputIdle(
2199 IN DWORD dwMilliseconds
,
2203 PW32PROCESS W32Process
;
2206 LARGE_INTEGER Timeout
;
2207 ULONGLONG StartTime
, Run
, Elapsed
= 0;
2209 UserEnterExclusive();
2211 Status
= ObReferenceObjectByHandle(hProcess
,
2212 PROCESS_QUERY_INFORMATION
,
2218 if (!NT_SUCCESS(Status
))
2221 SetLastNtError(Status
);
2225 W32Process
= (PW32PROCESS
)Process
->Win32Process
;
2228 ObDereferenceObject(Process
);
2230 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2234 EngCreateEvent((PEVENT
*)&W32Process
->InputIdleEvent
);
2236 Handles
[0] = Process
;
2237 Handles
[1] = W32Process
->InputIdleEvent
;
2241 ObDereferenceObject(Process
);
2243 return STATUS_SUCCESS
; /* no event to wait on */
2246 StartTime
= EngGetTickCount();
2248 Run
= dwMilliseconds
;
2250 DPRINT("WFII: waiting for %p\n", Handles
[1] );
2253 Timeout
.QuadPart
= Run
- Elapsed
;
2255 Status
= KeWaitForMultipleObjects( 2,
2261 dwMilliseconds
== INFINITE
? NULL
: &Timeout
,
2263 UserEnterExclusive();
2265 if (!NT_SUCCESS(Status
))
2267 SetLastNtError(Status
);
2268 Status
= WAIT_FAILED
;
2275 Status
= WAIT_FAILED
;
2281 co_IntPeekMessage( &Msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2285 case STATUS_USER_APC
:
2286 case STATUS_ALERTED
:
2287 case STATUS_TIMEOUT
:
2288 DPRINT1("WFII: timeout\n");
2289 Status
= STATUS_TIMEOUT
;
2293 DPRINT1("WFII: finished\n");
2294 Status
= STATUS_SUCCESS
;
2298 if (dwMilliseconds
!= INFINITE
)
2300 Elapsed
= EngGetTickCount() - StartTime
;
2303 Status
= STATUS_TIMEOUT
;
2310 if (W32Process
->InputIdleEvent
)
2312 EngDeleteEvent((PEVENT
)W32Process
->InputIdleEvent
);
2313 W32Process
->InputIdleEvent
= NULL
;
2315 ObDereferenceObject(Process
);