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 &Size
, 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
, Info
.LParamSize
);
1032 if (! NT_SUCCESS(Status
))
1034 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
1035 &Size
, 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 &Size
, 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
, Info
.LParamSize
);
1167 if (! NT_SUCCESS(Status
))
1169 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
1170 &Size
, 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();
1312 if (Wnd
== HWND_BROADCAST
)
1315 PWINDOW_OBJECT DesktopWindow
;
1318 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1319 List
= IntWinListChildren(DesktopWindow
);
1323 for (i
= 0; List
[i
]; i
++)
1324 UserPostMessage(List
[i
], Msg
, wParam
, lParam
);
1330 PWINDOW_OBJECT Window
;
1332 Window
= UserGetWindowObject(Wnd
);
1337 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
1339 DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd
);
1340 /* FIXME - last error code? */
1346 MsqPostQuitMessage(Window
->MessageQueue
, wParam
);
1350 UserModeMsg
.hwnd
= Wnd
;
1351 UserModeMsg
.message
= Msg
;
1352 UserModeMsg
.wParam
= wParam
;
1353 UserModeMsg
.lParam
= lParam
;
1354 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1355 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1356 if (! NT_SUCCESS(Status
))
1358 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1361 IntGetCursorLocation(pti
->Desktop
->WindowStation
,
1363 KeQueryTickCount(&LargeTickCount
);
1364 pti
->timeLast
= KernelModeMsg
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1365 MsqPostMessage(Window
->MessageQueue
, &KernelModeMsg
,
1366 NULL
!= MsgMemoryEntry
&& 0 != KernelModeMsg
.lParam
,
1376 NtUserPostMessage(HWND hWnd
,
1381 DECLARE_RETURN(BOOL
);
1383 DPRINT("Enter NtUserPostMessage\n");
1384 UserEnterExclusive();
1386 RETURN(UserPostMessage(hWnd
, Msg
, wParam
, lParam
));
1389 DPRINT("Leave NtUserPostMessage, ret=%i\n",_ret_
);
1397 NtUserPostThreadMessage(DWORD idThread
,
1402 MSG UserModeMsg
, KernelModeMsg
;
1404 PTHREADINFO pThread
;
1406 PMSGMEMORY MsgMemoryEntry
;
1407 DECLARE_RETURN(BOOL
);
1409 DPRINT("Enter NtUserPostThreadMessage\n");
1410 UserEnterExclusive();
1412 Status
= PsLookupThreadByThreadId((HANDLE
)(DWORD_PTR
)idThread
,&peThread
);
1414 if( Status
== STATUS_SUCCESS
)
1416 pThread
= (PTHREADINFO
)peThread
->Tcb
.Win32Thread
;
1417 if( !pThread
|| !pThread
->MessageQueue
)
1419 ObDereferenceObject( peThread
);
1423 UserModeMsg
.hwnd
= NULL
;
1424 UserModeMsg
.message
= Msg
;
1425 UserModeMsg
.wParam
= wParam
;
1426 UserModeMsg
.lParam
= lParam
;
1427 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1428 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1429 if (! NT_SUCCESS(Status
))
1431 ObDereferenceObject( peThread
);
1432 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1435 MsqPostMessage(pThread
->MessageQueue
, &KernelModeMsg
,
1436 NULL
!= MsgMemoryEntry
&& 0 != KernelModeMsg
.lParam
,
1438 ObDereferenceObject( peThread
);
1443 SetLastNtError( Status
);
1448 DPRINT("Leave NtUserPostThreadMessage, ret=%i\n",_ret_
);
1454 NtUserQuerySendMessage(DWORD Unknown0
)
1462 co_IntSendMessage(HWND hWnd
,
1467 ULONG_PTR Result
= 0;
1468 if(co_IntSendMessageTimeout(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
))
1470 return (LRESULT
)Result
;
1477 co_IntSendMessageTimeoutSingle(HWND hWnd
,
1487 PWINDOW_OBJECT Window
= NULL
;
1488 PMSGMEMORY MsgMemoryEntry
;
1489 INT lParamBufferSize
;
1490 LPARAM lParamPacked
;
1491 PTHREADINFO Win32Thread
;
1492 DECLARE_RETURN(LRESULT
);
1493 USER_REFERENCE_ENTRY Ref
;
1495 if (!(Window
= UserGetWindowObject(hWnd
)))
1500 UserRefObjectCo(Window
, &Ref
);
1502 Win32Thread
= PsGetCurrentThreadWin32Thread();
1504 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1506 if (NULL
!= Win32Thread
&&
1507 Window
->MessageQueue
== Win32Thread
->MessageQueue
)
1509 if (Win32Thread
->IsExiting
)
1511 /* Never send messages to exiting threads */
1515 /* See if this message type is present in the table */
1516 MsgMemoryEntry
= FindMsgMemory(Msg
);
1517 if (NULL
== MsgMemoryEntry
)
1519 lParamBufferSize
= -1;
1523 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1526 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
)))
1528 DPRINT1("Failed to pack message parameters\n");
1532 Result
= (ULONG_PTR
)co_IntCallWindowProc(Window
->Wnd
->WndProc
, !Window
->Wnd
->Unicode
, hWnd
, Msg
, wParam
,
1533 lParamPacked
,lParamBufferSize
);
1540 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1542 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
)))
1544 DPRINT1("Failed to unpack message parameters\n");
1551 if (uFlags
& SMTO_ABORTIFHUNG
&& MsqIsHung(Window
->MessageQueue
))
1553 /* FIXME - Set a LastError? */
1557 if (Window
->Status
& WINDOWSTATUS_DESTROYING
)
1559 /* FIXME - last error? */
1560 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1566 Status
= co_MsqSendMessage( Window
->MessageQueue
,
1572 (uFlags
& SMTO_BLOCK
),
1576 while ((STATUS_TIMEOUT
== Status
) &&
1577 (uFlags
& SMTO_NOTIMEOUTIFNOTHUNG
) &&
1578 !MsqIsHung(Window
->MessageQueue
));
1580 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1582 if (STATUS_TIMEOUT
== Status
)
1586 Microsoft Windows 2000: If GetLastError returns zero, then the function
1588 XP+ : If the function fails or times out, the return value is zero.
1589 To get extended error information, call GetLastError. If GetLastError
1590 returns ERROR_TIMEOUT, then the function timed out.
1592 SetLastWin32Error(ERROR_TIMEOUT
);
1595 else if (! NT_SUCCESS(Status
))
1597 SetLastNtError(Status
);
1604 if (Window
) UserDerefObjectCo(Window
);
1609 co_IntSendMessageTimeout(HWND hWnd
,
1617 PWINDOW_OBJECT DesktopWindow
;
1621 if (HWND_BROADCAST
!= hWnd
)
1623 return co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1626 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1627 if (NULL
== DesktopWindow
)
1629 SetLastWin32Error(ERROR_INTERNAL_ERROR
);
1633 Children
= IntWinListChildren(DesktopWindow
);
1634 if (NULL
== Children
)
1639 for (Child
= Children
; NULL
!= *Child
; Child
++)
1641 co_IntSendMessageTimeoutSingle(*Child
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1644 ExFreePool(Children
);
1646 return (LRESULT
) TRUE
;
1650 /* This function posts a message if the destination's message queue belongs to
1651 another thread, otherwise it sends the message. It does not support broadcast
1654 co_IntPostOrSendMessage(HWND hWnd
,
1661 PWINDOW_OBJECT Window
;
1663 if(hWnd
== HWND_BROADCAST
)
1668 if(!(Window
= UserGetWindowObject(hWnd
)))
1673 pti
= PsGetCurrentThreadWin32Thread();
1674 if(Window
->MessageQueue
!= pti
->MessageQueue
)
1676 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1680 if(!co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
)) {
1685 return (LRESULT
)Result
;
1689 co_IntDoSendMessage(HWND hWnd
,
1694 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1697 LRESULT Result
= TRUE
;
1699 PWINDOW_OBJECT Window
= NULL
;
1700 NTUSERSENDMESSAGEINFO Info
;
1703 PMSGMEMORY MsgMemoryEntry
;
1705 RtlZeroMemory(&Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1707 /* FIXME: Call hooks. */
1708 if (HWND_BROADCAST
!= hWnd
)
1710 Window
= UserGetWindowObject(hWnd
);
1713 /* Tell usermode to not touch this one */
1714 Info
.HandledByKernel
= TRUE
;
1715 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1722 /* FIXME: Check for an exiting window. */
1724 /* See if the current thread can handle the message */
1725 pti
= PsGetCurrentThreadWin32Thread();
1726 if (HWND_BROADCAST
!= hWnd
&& NULL
!= pti
&&
1727 Window
->MessageQueue
== pti
->MessageQueue
)
1729 /* Gather the information usermode needs to call the window proc directly */
1730 Info
.HandledByKernel
= FALSE
;
1732 Status
= MmCopyFromCaller(&(Info
.Ansi
), &(UnsafeInfo
->Ansi
),
1734 if (! NT_SUCCESS(Status
))
1736 Info
.Ansi
= ! Window
->Wnd
->Unicode
;
1739 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1741 if (Window
->Wnd
->IsSystem
)
1743 Info
.Proc
= (!Info
.Ansi
? Window
->Wnd
->WndProc
: Window
->Wnd
->WndProcExtra
);
1747 Info
.Ansi
= !Window
->Wnd
->Unicode
;
1748 Info
.Proc
= Window
->Wnd
->WndProc
;
1751 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, &Result
);
1756 /* Must be handled by other thread */
1757 // if (HWND_BROADCAST != hWnd)
1759 // UserDereferenceObject(Window);
1761 Info
.HandledByKernel
= TRUE
;
1762 UserModeMsg
.hwnd
= hWnd
;
1763 UserModeMsg
.message
= Msg
;
1764 UserModeMsg
.wParam
= wParam
;
1765 UserModeMsg
.lParam
= lParam
;
1766 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1767 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1768 if (! NT_SUCCESS(Status
))
1770 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1771 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1772 return (dsm
? 0 : -1);
1776 Result
= co_IntSendMessage(KernelModeMsg
.hwnd
, KernelModeMsg
.message
,
1777 KernelModeMsg
.wParam
, KernelModeMsg
.lParam
);
1781 Result
= co_IntSendMessageTimeout(KernelModeMsg
.hwnd
, KernelModeMsg
.message
,
1782 KernelModeMsg
.wParam
, KernelModeMsg
.lParam
,
1783 dsm
->uFlags
, dsm
->uTimeout
, &dsm
->Result
);
1785 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1786 if (! NT_SUCCESS(Status
))
1788 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1789 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1790 return(dsm
? 0 : -1);
1794 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1795 if (! NT_SUCCESS(Status
))
1797 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1800 return (LRESULT
)Result
;
1804 NtUserSendMessageTimeout(HWND hWnd
,
1811 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1815 DECLARE_RETURN(BOOL
);
1817 DPRINT("Enter NtUserSendMessageTimeout\n");
1818 UserEnterExclusive();
1820 dsm
.uFlags
= uFlags
;
1821 dsm
.uTimeout
= uTimeout
;
1822 Result
= co_IntDoSendMessage(hWnd
, Msg
, wParam
, lParam
, &dsm
, UnsafeInfo
);
1823 if(uResult
!= NULL
&& Result
!= 0)
1827 Status
= MmCopyToCaller(uResult
, &dsm
.Result
, sizeof(ULONG_PTR
));
1828 if(!NT_SUCCESS(Status
))
1830 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1837 DPRINT("Leave NtUserSendMessageTimeout, ret=%i\n",_ret_
);
1843 NtUserSendMessage(HWND Wnd
,
1847 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1849 DECLARE_RETURN(BOOL
);
1851 DPRINT("Enter NtUserSendMessage\n");
1852 UserEnterExclusive();
1854 RETURN(co_IntDoSendMessage(Wnd
, Msg
, wParam
, lParam
, NULL
, UnsafeInfo
));
1857 DPRINT("Leave NtUserSendMessage, ret=%i\n",_ret_
);
1864 UserSendNotifyMessage(HWND hWnd
,
1870 // Basicly the same as IntPostOrSendMessage
1871 if (hWnd
== HWND_BROADCAST
) //Handle Broadcast
1874 PWINDOW_OBJECT DesktopWindow
;
1877 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1878 List
= IntWinListChildren(DesktopWindow
);
1882 for (i
= 0; List
[i
]; i
++)
1884 UserSendNotifyMessage(List
[i
], Msg
, wParam
, lParam
);
1893 PWINDOW_OBJECT Window
;
1897 PMSGMEMORY MsgMemoryEntry
;
1899 if(!(Window
= UserGetWindowObject(hWnd
))) return FALSE
;
1901 pti
= PsGetCurrentThreadWin32Thread();
1902 if(Window
->MessageQueue
!= pti
->MessageQueue
)
1903 { // Send message w/o waiting for it.
1904 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1907 { // Handle message and callback.
1908 UserModeMsg
.hwnd
= hWnd
;
1909 UserModeMsg
.message
= Msg
;
1910 UserModeMsg
.wParam
= wParam
;
1911 UserModeMsg
.lParam
= lParam
;
1912 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1913 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1914 if (! NT_SUCCESS(Status
))
1916 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1919 Result
= co_IntSendMessageTimeoutSingle(
1920 KernelModeMsg
.hwnd
, KernelModeMsg
.message
,
1921 KernelModeMsg
.wParam
, KernelModeMsg
.lParam
,
1922 SMTO_NORMAL
, 0, &PResult
);
1924 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1925 if (! NT_SUCCESS(Status
))
1927 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1937 NtUserSendNotifyMessage(HWND hWnd
,
1942 DECLARE_RETURN(BOOL
);
1944 DPRINT("EnterNtUserSendNotifyMessage\n");
1945 UserEnterExclusive();
1947 RETURN(UserSendNotifyMessage(hWnd
, Msg
, wParam
, lParam
));
1950 DPRINT("Leave NtUserSendNotifyMessage, ret=%i\n",_ret_
);
1958 NtUserWaitMessage(VOID
)
1960 DECLARE_RETURN(BOOL
);
1962 DPRINT("EnterNtUserWaitMessage\n");
1963 UserEnterExclusive();
1965 RETURN(co_IntWaitMessage(NULL
, 0, 0));
1968 DPRINT("Leave NtUserWaitMessage, ret=%i\n",_ret_
);
1974 IntGetQueueStatus(BOOL ClearChanges
)
1977 PUSER_MESSAGE_QUEUE Queue
;
1979 DECLARE_RETURN(DWORD
);
1981 DPRINT("Enter IntGetQueueStatus\n");
1983 pti
= PsGetCurrentThreadWin32Thread();
1984 Queue
= pti
->MessageQueue
;
1986 Result
= MAKELONG(Queue
->QueueBits
, Queue
->ChangedBits
);
1989 Queue
->ChangedBits
= 0;
1995 DPRINT("Leave IntGetQueueStatus, ret=%i\n",_ret_
);
2000 IntInitMessagePumpHook()
2002 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
2004 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
++;
2011 IntUninitMessagePumpHook()
2013 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
2015 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
<= 0)
2019 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
--;
2032 ULONG_PTR ResultInfo
,
2033 DWORD dwType
, // fnID?
2036 LRESULT lResult
= 0;
2037 PWINDOW_OBJECT Window
= NULL
;
2038 USER_REFERENCE_ENTRY Ref
;
2040 UserEnterExclusive();
2042 /* Validate input */
2043 if (hWnd
&& (hWnd
!= INVALID_HANDLE_VALUE
) && !(Window
= UserGetWindowObject(hWnd
)))
2050 case FNID_DEFWINDOWPROC
:
2051 UserRefObjectCo(Window
, &Ref
);
2052 lResult
= IntDefWindowProc(Window
, Msg
, wParam
, lParam
, Ansi
);
2053 UserDerefObjectCo(Window
);
2055 case FNID_BROADCASTSYSTEMMESSAGE
:
2057 PBROADCASTPARM parm
;
2058 BOOL BadChk
= FALSE
;
2059 DWORD_PTR RetVal
= 0;
2066 ProbeForWrite((PVOID
)ResultInfo
,
2067 sizeof(BROADCASTPARM
),
2069 parm
= (PBROADCASTPARM
)ResultInfo
;
2071 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2081 if ( parm
->recipients
& BSM_ALLDESKTOPS
||
2082 parm
->recipients
== BSM_ALLCOMPONENTS
)
2085 else if (parm
->recipients
& BSM_APPLICATIONS
)
2087 if (parm
->flags
& BSF_QUERY
)
2089 if (parm
->flags
& BSF_FORCEIFHUNG
|| parm
->flags
& BSF_NOHANG
)
2091 co_IntSendMessageTimeout( HWND_BROADCAST
,
2099 else if (parm
->flags
& BSF_NOTIMEOUTIFNOTHUNG
)
2101 co_IntSendMessageTimeout( HWND_BROADCAST
,
2105 SMTO_NOTIMEOUTIFNOTHUNG
,
2111 co_IntSendMessageTimeout( HWND_BROADCAST
,
2120 else if (parm
->flags
& BSF_POSTMESSAGE
)
2122 lResult
= UserPostMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2124 else if ( parm
->flags
& BSF_SENDNOTIFYMESSAGE
)
2126 lResult
= UserSendNotifyMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2131 case FNID_SENDMESSAGECALLBACK
:
2133 // CallNextHook bypass.
2134 case FNID_CALLWNDPROC
:
2135 case FNID_CALLWNDPROCRET
:
2137 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
2138 PHOOK NextObj
, Hook
= ClientInfo
->phkCurrent
;
2140 if (!ClientInfo
|| !Hook
) break;
2142 UserReferenceObject(Hook
);
2144 if (Hook
->Thread
&& (Hook
->Thread
!= PsGetCurrentThread()))
2146 UserDereferenceObject(Hook
);
2150 NextObj
= IntGetNextHook(Hook
);
2151 ClientInfo
->phkCurrent
= NextObj
;
2153 if ( Hook
->HookId
== WH_CALLWNDPROC
)
2158 CWP
.wParam
= wParam
;
2159 CWP
.lParam
= lParam
;
2160 DPRINT("WH_CALLWNDPROC: Hook %x NextHook %x\n", Hook
, NextObj
);
2162 lResult
= co_IntCallHookProc( Hook
->HookId
,
2164 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2175 CWPR
.wParam
= wParam
;
2176 CWPR
.lParam
= lParam
;
2177 CWPR
.lResult
= ClientInfo
->dwHookData
;
2179 lResult
= co_IntCallHookProc( Hook
->HookId
,
2181 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2187 UserDereferenceObject(Hook
);
2188 lResult
= (LRESULT
) NextObj
;
2196 #define INFINITE 0xFFFFFFFF
2197 #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
2201 NtUserWaitForInputIdle(
2203 IN DWORD dwMilliseconds
,
2207 PW32PROCESS W32Process
;
2210 LARGE_INTEGER Timeout
;
2211 ULONGLONG StartTime
, Run
, Elapsed
= 0;
2213 UserEnterExclusive();
2215 Status
= ObReferenceObjectByHandle(hProcess
,
2216 PROCESS_QUERY_INFORMATION
,
2222 if (!NT_SUCCESS(Status
))
2225 SetLastNtError(Status
);
2229 W32Process
= (PW32PROCESS
)Process
->Win32Process
;
2232 ObDereferenceObject(Process
);
2234 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2238 EngCreateEvent((PEVENT
*)&W32Process
->InputIdleEvent
);
2240 Handles
[0] = Process
;
2241 Handles
[1] = W32Process
->InputIdleEvent
;
2245 ObDereferenceObject(Process
);
2247 return STATUS_SUCCESS
; /* no event to wait on */
2250 StartTime
= EngGetTickCount();
2252 Run
= dwMilliseconds
;
2254 DPRINT("WFII: waiting for %p\n", Handles
[1] );
2257 Timeout
.QuadPart
= Run
- Elapsed
;
2259 Status
= KeWaitForMultipleObjects( 2,
2265 dwMilliseconds
== INFINITE
? NULL
: &Timeout
,
2267 UserEnterExclusive();
2269 if (!NT_SUCCESS(Status
))
2271 SetLastNtError(Status
);
2272 Status
= WAIT_FAILED
;
2279 Status
= WAIT_FAILED
;
2285 co_IntPeekMessage( &Msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2289 case STATUS_USER_APC
:
2290 case STATUS_ALERTED
:
2291 case STATUS_TIMEOUT
:
2292 DPRINT1("WFII: timeout\n");
2293 Status
= STATUS_TIMEOUT
;
2297 DPRINT1("WFII: finished\n");
2298 Status
= STATUS_SUCCESS
;
2302 if (dwMilliseconds
!= INFINITE
)
2304 Elapsed
= EngGetTickCount() - StartTime
;
2307 Status
= STATUS_TIMEOUT
;
2314 if (W32Process
->InputIdleEvent
)
2316 EngDeleteEvent((PEVENT
)W32Process
->InputIdleEvent
);
2317 W32Process
->InputIdleEvent
= NULL
;
2319 ObDereferenceObject(Process
);