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 ( PWND Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
332 BOOL SameThread
= FALSE
;
335 if (Window
->head
.pti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
342 co_HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, SameThread
, (LPARAM
)&CWP
);
349 ( PWND Window
, HWND hWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*uResult
)
351 BOOL SameThread
= FALSE
;
354 if (Window
->head
.pti
== ((PTHREADINFO
)PsGetCurrentThreadWin32Thread()))
359 CWPR
.wParam
= wParam
;
360 CWPR
.lParam
= lParam
;
361 CWPR
.lResult
= *uResult
;
362 co_HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, SameThread
, (LPARAM
)&CWPR
);
367 IntDispatchMessage(PMSG pMsg
)
369 LARGE_INTEGER TickCount
;
372 PMSGMEMORY MsgMemoryEntry
;
373 INT lParamBufferSize
;
379 Window
= UserGetWindowObject(pMsg
->hwnd
);
380 if (!Window
) return 0;
383 if (((pMsg
->message
== WM_SYSTIMER
) ||
384 (pMsg
->message
== WM_TIMER
)) &&
387 if (pMsg
->message
== WM_TIMER
)
389 if (ValidateTimerCallback(PsGetCurrentThreadWin32Thread(),pMsg
->lParam
))
391 KeQueryTickCount(&TickCount
);
392 Time
= MsqCalculateMessageTime(&TickCount
);
393 return co_IntCallWindowProc((WNDPROC
)pMsg
->lParam
,
405 PTIMER pTimer
= FindSystemTimer(pMsg
);
406 if (pTimer
&& pTimer
->pfn
)
408 KeQueryTickCount(&TickCount
);
409 Time
= MsqCalculateMessageTime(&TickCount
);
410 pTimer
->pfn(pMsg
->hwnd
, WM_SYSTIMER
, (UINT
)pMsg
->wParam
, Time
);
416 if ( !Window
) return 0;
418 /* See if this message type is present in the table */
419 MsgMemoryEntry
= FindMsgMemory(pMsg
->message
);
420 if ( !MsgMemoryEntry
)
422 lParamBufferSize
= -1;
426 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, pMsg
->wParam
, pMsg
->lParam
);
429 if (! NT_SUCCESS(PackParam(&lParamPacked
, pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
, FALSE
)))
431 DPRINT1("Failed to pack message parameters\n");
435 retval
= co_IntCallWindowProc( Window
->lpfnWndProc
,
443 if (! NT_SUCCESS(UnpackParam(lParamPacked
, pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
, FALSE
)))
445 DPRINT1("Failed to unpack message parameters\n");
448 if (pMsg
->message
== WM_PAINT
)
450 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
451 HRGN hrgn
= IntSysCreateRectRgn( 0, 0, 0, 0 );
452 co_UserGetUpdateRgn( Window
, hrgn
, TRUE
);
453 REGION_FreeRgnByHandle( hrgn
);
459 co_IntSendHitTestMessages(PUSER_MESSAGE_QUEUE ThreadQueue
, LPMSG Msg
)
461 if(!Msg
->hwnd
|| ThreadQueue
->CaptureWindow
)
470 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
475 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
482 case WM_LBUTTONDBLCLK
:
483 case WM_MBUTTONDBLCLK
:
484 case WM_RBUTTONDBLCLK
:
485 case WM_XBUTTONDBLCLK
:
488 PSYSTEM_CURSORINFO CurInfo
;
489 CurInfo
= IntGetSysCursorInfo();
491 wParam
= (WPARAM
)(CurInfo
->ButtonsDown
);
493 co_IntSendMessage(Msg
->hwnd
, WM_MOUSEMOVE
, wParam
, Msg
->lParam
);
494 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(HTCLIENT
, Msg
->message
));
497 case WM_NCLBUTTONDOWN
:
498 case WM_NCMBUTTONDOWN
:
499 case WM_NCRBUTTONDOWN
:
500 case WM_NCXBUTTONDOWN
:
501 case WM_NCLBUTTONDBLCLK
:
502 case WM_NCMBUTTONDBLCLK
:
503 case WM_NCRBUTTONDBLCLK
:
504 case WM_NCXBUTTONDBLCLK
:
506 co_IntSendMessage(Msg
->hwnd
, WM_NCMOUSEMOVE
, (WPARAM
)Msg
->wParam
, Msg
->lParam
);
507 co_IntSendMessage(Msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)Msg
->hwnd
, MAKELPARAM(Msg
->wParam
, Msg
->message
));
514 co_IntActivateWindowMouse(
515 PUSER_MESSAGE_QUEUE ThreadQueue
,
523 ASSERT_REFS_CO(MsgWindow
);
525 if(*HitTest
== (USHORT
)HTTRANSPARENT
)
527 /* eat the message, search again! */
531 Parent
= IntGetParent(MsgWindow
);//fixme: deref retval?
533 /* If no parent window, pass MsgWindows HWND as wParam. Fixes bug #3111 */
534 Result
= co_IntSendMessage(MsgWindow
->head
.h
,
536 (WPARAM
) (Parent
? Parent
->head
.h
: MsgWindow
->head
.h
),
537 (LPARAM
)MAKELONG(*HitTest
, Msg
->message
)
542 case MA_NOACTIVATEANDEAT
:
546 case MA_ACTIVATEANDEAT
:
547 co_IntMouseActivateWindow(MsgWindow
);
551 co_IntMouseActivateWindow(MsgWindow
);
559 co_IntTranslateMouseMessage(
560 PUSER_MESSAGE_QUEUE ThreadQueue
,
566 USER_REFERENCE_ENTRY Ref
, DesktopRef
;
568 if(!(Window
= UserGetWindowObject(Msg
->hwnd
)))
570 /* let's just eat the message?! */
576 UserRefObjectCo(Window
, &Ref
);
578 if ( ThreadQueue
== Window
->head
.pti
->MessageQueue
&&
579 ThreadQueue
->CaptureWindow
!= Window
->head
.h
)
581 /* only send WM_NCHITTEST messages if we're not capturing the window! */
584 *HitTest
= co_IntSendMessage(Window
->head
.h
, WM_NCHITTEST
, 0,
585 MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
));
587 /* else we are going to see this message again, but then with Remove == TRUE */
589 if (*HitTest
== (USHORT
)HTTRANSPARENT
)
592 HWND hDesktop
= IntGetDesktopWindow();
594 if ((DesktopWindow
= UserGetWindowObject(hDesktop
)))
598 UserRefObjectCo(DesktopWindow
, &DesktopRef
);
600 co_WinPosWindowFromPoint(DesktopWindow
, Window
->head
.pti
->MessageQueue
, &Msg
->pt
, &Wnd
);
605 /* post the message to the other window */
606 Msg
->hwnd
= Wnd
->head
.h
;
607 if(!(Wnd
->state
& WNDS_DESTROYED
))
609 MsqPostMessage(Wnd
->head
.pti
->MessageQueue
, Msg
, FALSE
,
610 Msg
->message
== WM_MOUSEMOVE
? QS_MOUSEMOVE
:
614 /* eat the message */
615 UserDereferenceObject(Wnd
);
616 UserDerefObjectCo(DesktopWindow
);
617 UserDerefObjectCo(Window
);
620 UserDereferenceObject(Wnd
);
623 UserDerefObjectCo(DesktopWindow
);
628 if ( gspv
.bMouseClickLock
&&
629 ( (Msg
->message
== WM_LBUTTONUP
) ||
630 (Msg
->message
== WM_LBUTTONDOWN
) ) )
632 if (MsqIsClkLck(Msg
, Remove
))
634 // FIXME: drop the message, hack: use WM_NULL
635 Msg
->message
= WM_NULL
;
639 if (IS_BTN_MESSAGE(Msg
->message
, DOWN
))
641 /* generate double click messages, if necessary */
642 if ((((*HitTest
) != HTCLIENT
) ||
643 (Window
->pcls
->style
& CS_DBLCLKS
)) &&
644 MsqIsDblClk(Msg
, Remove
))
646 Msg
->message
+= WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
;
650 if(Msg
->message
!= WM_MOUSEWHEEL
)
653 if ((*HitTest
) != HTCLIENT
)
655 Msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
656 if ( (Msg
->message
== WM_NCRBUTTONUP
) &&
657 (((*HitTest
) == HTCAPTION
) || ((*HitTest
) == HTSYSMENU
)) )
659 Msg
->message
= WM_CONTEXTMENU
;
660 Msg
->wParam
= (WPARAM
)Window
->head
.h
;
664 Msg
->wParam
= *HitTest
;
666 Msg
->lParam
= MAKELONG(Msg
->pt
.x
, Msg
->pt
.y
);
668 else if ( ThreadQueue
->MoveSize
== NULL
&&
669 ThreadQueue
->MenuOwner
== NULL
)
671 /* NOTE: Msg->pt should remain in screen coordinates. -- FiN */
672 Msg
->lParam
= MAKELONG(
673 Msg
->pt
.x
- (WORD
)Window
->rcClient
.left
,
674 Msg
->pt
.y
- (WORD
)Window
->rcClient
.top
);
678 UserDerefObjectCo(Window
);
682 BOOL
ProcessMouseMessage(MSG
* Msg
, BOOLEAN RemoveMessages
)
684 MOUSEHOOKSTRUCT MHook
;
687 PUSER_MESSAGE_QUEUE ThreadQueue
;
688 USER_REFERENCE_ENTRY Ref
;
689 USHORT HitTest
= HTNOWHERE
;
691 pti
= PsGetCurrentThreadWin32Thread();
692 ThreadQueue
= pti
->MessageQueue
;
696 PWND MsgWindow
= NULL
;
698 /* Mouse message process */
701 ( MsgWindow
= UserGetWindowObject(Msg
->hwnd
) ) &&
702 Msg
->message
>= WM_MOUSEFIRST
&&
703 Msg
->message
<= WM_MOUSELAST
)
707 UserRefObjectCo(MsgWindow
, &Ref
);
709 if ( co_IntTranslateMouseMessage( ThreadQueue
,
713 /* FIXME - check message filter again, if the message doesn't match anymore,
716 UserDerefObjectCo(MsgWindow
);
717 /* eat the message, search again */
721 if(ThreadQueue
->CaptureWindow
== NULL
)
723 co_IntSendHitTestMessages(ThreadQueue
, Msg
);
725 if ( ( Msg
->message
!= WM_MOUSEMOVE
&&
726 Msg
->message
!= WM_NCMOUSEMOVE
) &&
727 IS_BTN_MESSAGE(Msg
->message
, DOWN
) &&
728 co_IntActivateWindowMouse(ThreadQueue
, Msg
, MsgWindow
, &HitTest
) )
730 UserDerefObjectCo(MsgWindow
);
731 /* eat the message, search again */
736 UserDerefObjectCo(MsgWindow
);
740 co_IntSendHitTestMessages(ThreadQueue
, Msg
);
747 Msg
->message
>= WM_MOUSEFIRST
&&
748 Msg
->message
<= WM_MOUSELAST
) &&
749 co_IntTranslateMouseMessage( ThreadQueue
,
753 /* FIXME - check message filter again, if the message doesn't match anymore,
756 /* eat the message, search again */
760 pti
->rpdesk
->htEx
= HitTest
; /* Now set the capture hit. */
762 Event
.message
= Msg
->message
;
763 Event
.time
= Msg
->time
;
764 Event
.hwnd
= Msg
->hwnd
;
765 Event
.paramL
= Msg
->pt
.x
;
766 Event
.paramH
= Msg
->pt
.y
;
767 co_HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&Event
);
771 MHook
.hwnd
= Msg
->hwnd
;
772 MHook
.wHitTestCode
= HitTest
;
773 MHook
.dwExtraInfo
= 0;
774 if (co_HOOK_CallHooks( WH_MOUSE
,
775 RemoveMessages
? HC_ACTION
: HC_NOREMOVE
,
780 MHook
.hwnd
= Msg
->hwnd
;
781 MHook
.wHitTestCode
= HitTest
;
782 MHook
.dwExtraInfo
= 0;
783 co_HOOK_CallHooks( WH_CBT
,
793 BOOL
ProcessKeyboardMessage(MSG
* Msg
, BOOLEAN RemoveMessages
)
797 Event
.message
= Msg
->message
;
798 Event
.hwnd
= Msg
->hwnd
;
799 Event
.time
= Msg
->time
;
800 Event
.paramL
= (Msg
->wParam
& 0xFF) | (HIWORD(Msg
->lParam
) << 8);
801 Event
.paramH
= Msg
->lParam
& 0x7FFF;
802 if (HIWORD(Msg
->lParam
) & 0x0100) Event
.paramH
|= 0x8000;
803 co_HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&Event
);
805 if (co_HOOK_CallHooks( WH_KEYBOARD
,
806 RemoveMessages
? HC_ACTION
: HC_NOREMOVE
,
810 /* skip this message */
811 co_HOOK_CallHooks( WH_CBT
,
820 BOOL
ProcessHardwareMessage(MSG
* Msg
, BOOLEAN RemoveMessages
)
822 if ( IS_MOUSE_MESSAGE(Msg
->message
))
824 if (!ProcessMouseMessage(Msg
, RemoveMessages
))
829 else if ( IS_KBD_MESSAGE(Msg
->message
))
831 if(!ProcessKeyboardMessage(Msg
, RemoveMessages
))
840 * Internal version of PeekMessage() doing all the work
843 co_IntPeekMessage( PUSER_MESSAGE Msg
,
850 LARGE_INTEGER LargeTickCount
;
851 PUSER_MESSAGE_QUEUE ThreadQueue
;
852 PUSER_MESSAGE Message
;
855 pti
= PsGetCurrentThreadWin32Thread();
856 ThreadQueue
= pti
->MessageQueue
;
858 RemoveMessages
= RemoveMsg
& PM_REMOVE
;
862 KeQueryTickCount(&LargeTickCount
);
863 ThreadQueue
->LastMsgRead
= LargeTickCount
.u
.LowPart
;
865 /* Dispatch sent messages here. */
866 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
869 /* Now look for a quit message. */
871 if (ThreadQueue
->QuitPosted
)
873 /* According to the PSDK, WM_QUIT messages are always returned, regardless
874 of the filter specified */
875 Msg
->Msg
.hwnd
= NULL
;
876 Msg
->Msg
.message
= WM_QUIT
;
877 Msg
->Msg
.wParam
= ThreadQueue
->QuitExitCode
;
881 ThreadQueue
->QuitPosted
= FALSE
;
887 /* Now check for normal messages. */
888 if (co_MsqFindMessage( ThreadQueue
,
896 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
899 MsqDestroyMessage(Message
);
904 /* Check for hardware events. */
905 if(co_MsqFindMessage( ThreadQueue
,
913 RtlCopyMemory(Msg
, Message
, sizeof(USER_MESSAGE
));
916 MsqDestroyMessage(Message
);
919 if(!ProcessHardwareMessage(&Msg
->Msg
, RemoveMessages
))
925 /* Check for sent messages again. */
926 while (co_MsqDispatchOneSentMessage(ThreadQueue
))
929 /* Check for paint messages. */
930 if( IntGetPaintMessage( Window
,
940 if (PostTimerMessages(Window
))
949 // The WH_GETMESSAGE hook enables an application to monitor messages about to
950 // be returned by the GetMessage or PeekMessage function.
952 co_HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, RemoveMsg
& PM_REMOVE
, (LPARAM
)&Msg
->Msg
);
956 static NTSTATUS FASTCALL
957 CopyMsgToKernelMem(MSG
*KernelModeMsg
, MSG
*UserModeMsg
, PMSGMEMORY MsgMemoryEntry
)
964 *KernelModeMsg
= *UserModeMsg
;
966 /* See if this message type is present in the table */
967 if (NULL
== MsgMemoryEntry
)
969 /* Not present, no copying needed */
970 return STATUS_SUCCESS
;
973 /* Determine required size */
974 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
978 /* Allocate kernel mem */
979 KernelMem
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_MSG
);
980 if (NULL
== KernelMem
)
982 DPRINT1("Not enough memory to copy message to kernel mem\n");
983 return STATUS_NO_MEMORY
;
985 KernelModeMsg
->lParam
= (LPARAM
) KernelMem
;
987 /* Copy data if required */
988 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_READ
))
990 Status
= MmCopyFromCaller(KernelMem
, (PVOID
) UserModeMsg
->lParam
, Size
);
991 if (! NT_SUCCESS(Status
))
993 DPRINT1("Failed to copy message to kernel: invalid usermode buffer\n");
994 ExFreePoolWithTag(KernelMem
, TAG_MSG
);
1000 /* Make sure we don't pass any secrets to usermode */
1001 RtlZeroMemory(KernelMem
, Size
);
1006 KernelModeMsg
->lParam
= 0;
1009 return STATUS_SUCCESS
;
1012 static NTSTATUS FASTCALL
1013 CopyMsgToUserMem(MSG
*UserModeMsg
, MSG
*KernelModeMsg
)
1016 PMSGMEMORY MsgMemoryEntry
;
1019 /* See if this message type is present in the table */
1020 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
->message
);
1021 if (NULL
== MsgMemoryEntry
)
1023 /* Not present, no copying needed */
1024 return STATUS_SUCCESS
;
1027 /* Determine required size */
1028 Size
= MsgMemorySize(MsgMemoryEntry
, UserModeMsg
->wParam
, UserModeMsg
->lParam
);
1032 /* Copy data if required */
1033 if (0 != (MsgMemoryEntry
->Flags
& MMS_FLAG_WRITE
))
1035 Status
= MmCopyToCaller((PVOID
) UserModeMsg
->lParam
, (PVOID
) KernelModeMsg
->lParam
, Size
);
1036 if (! NT_SUCCESS(Status
))
1038 DPRINT1("Failed to copy message from kernel: invalid usermode buffer\n");
1039 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1044 ExFreePool((PVOID
) KernelModeMsg
->lParam
);
1047 return STATUS_SUCCESS
;
1050 static BOOL FASTCALL
1051 co_IntWaitMessage( PWND Window
,
1056 PUSER_MESSAGE_QUEUE ThreadQueue
;
1057 NTSTATUS Status
= STATUS_SUCCESS
;
1060 pti
= PsGetCurrentThreadWin32Thread();
1061 ThreadQueue
= pti
->MessageQueue
;
1065 if ( co_IntPeekMessage( &Msg
,
1073 /* Nothing found. Wait for new messages. */
1074 Status
= co_MsqWaitForNewMessages( ThreadQueue
,
1079 while ( (STATUS_WAIT_0
<= Status
&& Status
<= STATUS_WAIT_63
) ||
1080 STATUS_TIMEOUT
== Status
);
1082 if (!NT_SUCCESS(Status
))
1084 SetLastNtError(Status
);
1085 DPRINT1("Exit co_IntWaitMessage on error!\n");
1092 co_IntGetPeekMessage( PMSG pMsg
,
1103 if ( hWnd
== HWND_TOPMOST
||
1104 hWnd
== HWND_BROADCAST
)
1107 /* Validate input */
1108 if (hWnd
&& hWnd
!= HWND_BOTTOM
)
1110 if (!(Window
= UserGetWindowObject(hWnd
)))
1120 Window
= (PWND
)hWnd
;
1123 if (MsgFilterMax
< MsgFilterMin
)
1131 Present
= co_IntPeekMessage( &Msg
,
1138 RtlCopyMemory( pMsg
, &Msg
.Msg
, sizeof(MSG
));
1141 return (WM_QUIT
!= pMsg
->message
);
1146 if ( bGMSG
&& !co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
) )
1152 if (!(RemoveMsg
& PM_NOYIELD
))
1154 // Yield this thread!
1157 UserEnterExclusive();
1158 // Fall through to fail.
1162 while( bGMSG
&& !Present
);
1168 UserPostThreadMessage( DWORD idThread
,
1175 PTHREADINFO pThread
;
1176 LARGE_INTEGER LargeTickCount
;
1179 DPRINT1("UserPostThreadMessage wParam 0x%x lParam 0x%x\n", wParam
,lParam
);
1181 if (FindMsgMemory(Msg
) != 0)
1183 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1187 Status
= PsLookupThreadByThreadId((HANDLE
)idThread
,&peThread
);
1189 if( Status
== STATUS_SUCCESS
)
1191 pThread
= (PTHREADINFO
)peThread
->Tcb
.Win32Thread
;
1193 !pThread
->MessageQueue
||
1194 (pThread
->TIF_flags
& TIF_INCLEANUP
))
1196 ObDereferenceObject( peThread
);
1200 Message
.hwnd
= NULL
;
1201 Message
.message
= Msg
;
1202 Message
.wParam
= wParam
;
1203 Message
.lParam
= lParam
;
1204 Message
.pt
= gpsi
->ptCursor
;
1206 KeQueryTickCount(&LargeTickCount
);
1207 pThread
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1208 MsqPostMessage(pThread
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1209 ObDereferenceObject( peThread
);
1214 SetLastNtError( Status
);
1220 UserPostMessage( HWND Wnd
,
1227 LARGE_INTEGER LargeTickCount
;
1229 if (FindMsgMemory(Msg
) != 0)
1231 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1236 return UserPostThreadMessage( PtrToInt(PsGetCurrentThreadId()),
1241 if (Wnd
== HWND_BROADCAST
)
1247 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1248 List
= IntWinListChildren(DesktopWindow
);
1252 for (i
= 0; List
[i
]; i
++)
1253 UserPostMessage(List
[i
], Msg
, wParam
, lParam
);
1261 Window
= UserGetWindowObject(Wnd
);
1267 pti
= Window
->head
.pti
;
1268 if ( pti
->TIF_flags
& TIF_INCLEANUP
)
1270 DPRINT1("Attempted to post message to window 0x%x when the thread is in cleanup!\n", Wnd
);
1274 if ( Window
->state
& WNDS_DESTROYED
)
1276 DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd
);
1277 /* FIXME - last error code? */
1283 MsqPostQuitMessage(Window
->head
.pti
->MessageQueue
, wParam
);
1288 Message
.message
= Msg
;
1289 Message
.wParam
= wParam
;
1290 Message
.lParam
= lParam
;
1291 Message
.pt
= gpsi
->ptCursor
;
1292 KeQueryTickCount(&LargeTickCount
);
1293 pti
->timeLast
= Message
.time
= MsqCalculateMessageTime(&LargeTickCount
);
1294 MsqPostMessage(Window
->head
.pti
->MessageQueue
, &Message
, FALSE
, QS_POSTMESSAGE
);
1302 co_IntSendMessage( HWND hWnd
,
1307 ULONG_PTR Result
= 0;
1308 if(co_IntSendMessageTimeout(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
))
1310 return (LRESULT
)Result
;
1317 co_IntSendMessageTimeoutSingle( HWND hWnd
,
1323 ULONG_PTR
*uResult
)
1328 PMSGMEMORY MsgMemoryEntry
;
1329 INT lParamBufferSize
;
1330 LPARAM lParamPacked
;
1331 PTHREADINFO Win32Thread
;
1332 DECLARE_RETURN(LRESULT
);
1333 USER_REFERENCE_ENTRY Ref
;
1335 if (!(Window
= UserGetWindowObject(hWnd
)))
1340 UserRefObjectCo(Window
, &Ref
);
1342 Win32Thread
= PsGetCurrentThreadWin32Thread();
1344 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1346 if ( NULL
!= Win32Thread
&&
1347 Window
->head
.pti
->MessageQueue
== Win32Thread
->MessageQueue
)
1349 if (Win32Thread
->TIF_flags
& TIF_INCLEANUP
)
1351 /* Never send messages to exiting threads */
1355 /* See if this message type is present in the table */
1356 MsgMemoryEntry
= FindMsgMemory(Msg
);
1357 if (NULL
== MsgMemoryEntry
)
1359 lParamBufferSize
= -1;
1363 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1366 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
, FALSE
)))
1368 DPRINT1("Failed to pack message parameters\n");
1372 Result
= (ULONG_PTR
)co_IntCallWindowProc( Window
->lpfnWndProc
,
1384 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1386 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
, FALSE
)))
1388 DPRINT1("Failed to unpack message parameters\n");
1395 if (uFlags
& SMTO_ABORTIFHUNG
&& MsqIsHung(Window
->head
.pti
->MessageQueue
))
1397 /* FIXME - Set a LastError? */
1401 if (Window
->state
& WNDS_DESTROYED
)
1403 /* FIXME - last error? */
1404 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1410 Status
= co_MsqSendMessage( Window
->head
.pti
->MessageQueue
,
1416 (uFlags
& SMTO_BLOCK
),
1420 while ((STATUS_TIMEOUT
== Status
) &&
1421 (uFlags
& SMTO_NOTIMEOUTIFNOTHUNG
) &&
1422 !MsqIsHung(Window
->head
.pti
->MessageQueue
));
1424 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1426 if (STATUS_TIMEOUT
== Status
)
1430 Microsoft Windows 2000: If GetLastError returns zero, then the function
1432 XP+ : If the function fails or times out, the return value is zero.
1433 To get extended error information, call GetLastError. If GetLastError
1434 returns ERROR_TIMEOUT, then the function timed out.
1436 SetLastWin32Error(ERROR_TIMEOUT
);
1439 else if (! NT_SUCCESS(Status
))
1441 SetLastNtError(Status
);
1448 if (Window
) UserDerefObjectCo(Window
);
1453 co_IntSendMessageTimeout( HWND hWnd
,
1459 ULONG_PTR
*uResult
)
1465 if (HWND_BROADCAST
!= hWnd
)
1467 return co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1470 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1471 if (NULL
== DesktopWindow
)
1473 SetLastWin32Error(ERROR_INTERNAL_ERROR
);
1477 Children
= IntWinListChildren(DesktopWindow
);
1478 if (NULL
== Children
)
1483 for (Child
= Children
; NULL
!= *Child
; Child
++)
1485 co_IntSendMessageTimeoutSingle(*Child
, Msg
, wParam
, lParam
, uFlags
, uTimeout
, uResult
);
1488 ExFreePool(Children
);
1490 return (LRESULT
) TRUE
;
1493 LRESULT FASTCALL
co_IntSendMessageNoWait(HWND hWnd
,
1498 ULONG_PTR Result
= 0;
1499 co_IntSendMessageWithCallBack(hWnd
,
1510 co_IntSendMessageWithCallBack( HWND hWnd
,
1514 SENDASYNCPROC CompletionCallback
,
1515 ULONG_PTR CompletionCallbackContext
,
1520 PMSGMEMORY MsgMemoryEntry
;
1521 INT lParamBufferSize
;
1522 LPARAM lParamPacked
;
1523 PTHREADINFO Win32Thread
;
1524 DECLARE_RETURN(LRESULT
);
1525 USER_REFERENCE_ENTRY Ref
;
1526 PUSER_SENT_MESSAGE Message
;
1528 if (!(Window
= UserGetWindowObject(hWnd
)))
1533 UserRefObjectCo(Window
, &Ref
);
1535 if (Window
->state
& WNDS_DESTROYED
)
1537 /* FIXME - last error? */
1538 DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd
);
1542 Win32Thread
= PsGetCurrentThreadWin32Thread();
1544 IntCallWndProc( Window
, hWnd
, Msg
, wParam
, lParam
);
1546 if (Win32Thread
== NULL
)
1552 if (Win32Thread
->TIF_flags
& TIF_INCLEANUP
)
1554 /* Never send messages to exiting threads */
1558 /* See if this message type is present in the table */
1559 MsgMemoryEntry
= FindMsgMemory(Msg
);
1560 if (NULL
== MsgMemoryEntry
)
1562 lParamBufferSize
= -1;
1566 lParamBufferSize
= MsgMemorySize(MsgMemoryEntry
, wParam
, lParam
);
1569 if (! NT_SUCCESS(PackParam(&lParamPacked
, Msg
, wParam
, lParam
, Window
->head
.pti
->MessageQueue
!= Win32Thread
->MessageQueue
)))
1571 DPRINT1("Failed to pack message parameters\n");
1575 /* If this is not a callback and it can be sent now, then send it. */
1576 if ((Window
->head
.pti
->MessageQueue
== Win32Thread
->MessageQueue
) && (CompletionCallback
== NULL
))
1579 Result
= (ULONG_PTR
)co_IntCallWindowProc( Window
->lpfnWndProc
,
1592 IntCallWndProcRet( Window
, hWnd
, Msg
, wParam
, lParam
, (LRESULT
*)uResult
);
1594 if ((Window
->head
.pti
->MessageQueue
== Win32Thread
->MessageQueue
) && (CompletionCallback
== NULL
))
1596 if (! NT_SUCCESS(UnpackParam(lParamPacked
, Msg
, wParam
, lParam
, FALSE
)))
1598 DPRINT1("Failed to unpack message parameters\n");
1603 if(!(Message
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(USER_SENT_MESSAGE
), TAG_USRMSG
)))
1605 DPRINT1("MsqSendMessage(): Not enough memory to allocate a message");
1606 return STATUS_INSUFFICIENT_RESOURCES
;
1609 Message
->Msg
.hwnd
= hWnd
;
1610 Message
->Msg
.message
= Msg
;
1611 Message
->Msg
.wParam
= wParam
;
1612 Message
->Msg
.lParam
= lParamPacked
;
1613 Message
->CompletionEvent
= NULL
;
1614 Message
->Result
= 0;
1615 Message
->SenderQueue
= NULL
; //Win32Thread->MessageQueue;
1617 IntReferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
1618 Message
->CompletionCallback
= CompletionCallback
;
1619 Message
->CompletionCallbackContext
= CompletionCallbackContext
;
1620 Message
->HookMessage
= MSQ_NORMAL
| MSQ_SENTNOWAIT
;
1621 Message
->HasPackedLParam
= (lParamBufferSize
> 0);
1623 InsertTailList(&Window
->head
.pti
->MessageQueue
->SentMessagesListHead
, &Message
->ListEntry
);
1624 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
1629 if (Window
) UserDerefObjectCo(Window
);
1633 /* This function posts a message if the destination's message queue belongs to
1634 another thread, otherwise it sends the message. It does not support broadcast
1637 co_IntPostOrSendMessage( HWND hWnd
,
1646 if ( hWnd
== HWND_BROADCAST
)
1651 if(!(Window
= UserGetWindowObject(hWnd
)))
1656 pti
= PsGetCurrentThreadWin32Thread();
1658 if ( Window
->head
.pti
->MessageQueue
!= pti
->MessageQueue
&&
1659 FindMsgMemory(Msg
) == 0 )
1661 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1665 if ( !co_IntSendMessageTimeoutSingle(hWnd
, Msg
, wParam
, lParam
, SMTO_NORMAL
, 0, &Result
) )
1671 return (LRESULT
)Result
;
1675 co_IntDoSendMessage( HWND hWnd
,
1680 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1683 LRESULT Result
= TRUE
;
1686 NTUSERSENDMESSAGEINFO Info
;
1689 PMSGMEMORY MsgMemoryEntry
;
1691 RtlZeroMemory(&Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1693 /* FIXME: Call hooks. */
1694 if (HWND_BROADCAST
!= hWnd
)
1696 Window
= UserGetWindowObject(hWnd
);
1699 /* Tell usermode to not touch this one */
1700 Info
.HandledByKernel
= TRUE
;
1701 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1706 /* Check for an exiting window. */
1707 if (Window
&& Window
->state
& WNDS_DESTROYED
)
1709 DPRINT1("co_IntDoSendMessage Window Exiting!\n");
1712 /* See if the current thread can handle the message */
1713 pti
= PsGetCurrentThreadWin32Thread();
1715 // This is checked in user mode!!!!!!!
1716 if ( HWND_BROADCAST
!= hWnd
&&
1718 Window
->head
.pti
->MessageQueue
== pti
->MessageQueue
&&
1719 !ISITHOOKED(WH_CALLWNDPROC
) &&
1720 !ISITHOOKED(WH_CALLWNDPROCRET
) &&
1721 ( Msg
< WM_DDE_FIRST
|| Msg
> WM_DDE_LAST
) )
1723 /* Gather the information usermode needs to call the window proc directly */
1724 Info
.HandledByKernel
= FALSE
;
1726 Status
= MmCopyFromCaller(&(Info
.Ansi
), &(UnsafeInfo
->Ansi
),
1728 if (! NT_SUCCESS(Status
))
1730 Info
.Ansi
= ! Window
->Unicode
;
1733 Info
.Ansi
= !Window
->Unicode
;
1734 Info
.Proc
= Window
->lpfnWndProc
;
1738 /* Must be handled by other thread */
1739 // if (HWND_BROADCAST != hWnd)
1741 // UserDereferenceObject(Window);
1743 Info
.HandledByKernel
= TRUE
;
1744 UserModeMsg
.hwnd
= hWnd
;
1745 UserModeMsg
.message
= Msg
;
1746 UserModeMsg
.wParam
= wParam
;
1747 UserModeMsg
.lParam
= lParam
;
1748 MsgMemoryEntry
= FindMsgMemory(UserModeMsg
.message
);
1750 Status
= CopyMsgToKernelMem(&KernelModeMsg
, &UserModeMsg
, MsgMemoryEntry
);
1751 if (! NT_SUCCESS(Status
))
1753 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1754 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1755 return (dsm
? 0 : -1);
1760 Result
= co_IntSendMessage( KernelModeMsg
.hwnd
,
1761 KernelModeMsg
.message
,
1762 KernelModeMsg
.wParam
,
1763 KernelModeMsg
.lParam
);
1767 Result
= co_IntSendMessageTimeout( KernelModeMsg
.hwnd
,
1768 KernelModeMsg
.message
,
1769 KernelModeMsg
.wParam
,
1770 KernelModeMsg
.lParam
,
1776 Status
= CopyMsgToUserMem(&UserModeMsg
, &KernelModeMsg
);
1777 if (! NT_SUCCESS(Status
))
1779 MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1780 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1781 return(dsm
? 0 : -1);
1785 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERSENDMESSAGEINFO
));
1786 if (! NT_SUCCESS(Status
))
1788 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1791 return (LRESULT
)Result
;
1796 UserSendNotifyMessage( HWND hWnd
,
1803 if (FindMsgMemory(Msg
) != 0)
1805 SetLastWin32Error(ERROR_MESSAGE_SYNC_ONLY
);
1809 // Basicly the same as IntPostOrSendMessage
1810 if (hWnd
== HWND_BROADCAST
) //Handle Broadcast
1816 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
1817 List
= IntWinListChildren(DesktopWindow
);
1821 for (i
= 0; List
[i
]; i
++)
1823 UserSendNotifyMessage(List
[i
], Msg
, wParam
, lParam
);
1834 if ( !(Window
= UserGetWindowObject(hWnd
)) ) return FALSE
;
1836 pti
= PsGetCurrentThreadWin32Thread();
1838 if (Window
->head
.pti
->MessageQueue
!= pti
->MessageQueue
)
1839 { // Send message w/o waiting for it.
1840 Result
= UserPostMessage(hWnd
, Msg
, wParam
, lParam
);
1843 { // Handle message and callback.
1844 Result
= co_IntSendMessageTimeoutSingle( hWnd
,
1858 IntGetQueueStatus(BOOL ClearChanges
)
1861 PUSER_MESSAGE_QUEUE Queue
;
1863 DECLARE_RETURN(DWORD
);
1865 DPRINT("Enter IntGetQueueStatus\n");
1867 pti
= PsGetCurrentThreadWin32Thread();
1868 Queue
= pti
->MessageQueue
;
1870 Result
= MAKELONG(Queue
->QueueBits
, Queue
->ChangedBits
);
1873 Queue
->ChangedBits
= 0;
1879 DPRINT("Leave IntGetQueueStatus, ret=%i\n",_ret_
);
1884 IntInitMessagePumpHook()
1886 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1888 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
++;
1895 IntUninitMessagePumpHook()
1897 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
)
1899 if (((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
<= 0)
1903 ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->pcti
->dwcPumpHook
--;
1909 /** Functions ******************************************************************/
1912 NtUserPostMessage(HWND hWnd
,
1917 DECLARE_RETURN(BOOL
);
1919 DPRINT("Enter NtUserPostMessage\n");
1920 UserEnterExclusive();
1922 RETURN( UserPostMessage(hWnd
, Msg
, wParam
, lParam
));
1925 DPRINT("Leave NtUserPostMessage, ret=%i\n",_ret_
);
1931 NtUserPostThreadMessage(DWORD idThread
,
1936 DECLARE_RETURN(BOOL
);
1938 DPRINT("Enter NtUserPostThreadMessage\n");
1939 UserEnterExclusive();
1941 RETURN( UserPostThreadMessage( idThread
,
1947 DPRINT("Leave NtUserPostThreadMessage, ret=%i\n",_ret_
);
1953 NtUserQuerySendMessage(DWORD Unknown0
)
1961 ////////// API on the way out!
1963 NtUserSendMessageTimeout( HWND hWnd
,
1970 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
1974 DECLARE_RETURN(BOOL
);
1976 DPRINT("Enter NtUserSendMessageTimeout\n");
1977 UserEnterExclusive();
1979 dsm
.uFlags
= uFlags
;
1980 dsm
.uTimeout
= uTimeout
;
1981 Result
= co_IntDoSendMessage(hWnd
, Msg
, wParam
, lParam
, &dsm
, UnsafeInfo
);
1982 if(uResult
!= NULL
&& Result
!= 0)
1986 Status
= MmCopyToCaller(uResult
, &dsm
.Result
, sizeof(ULONG_PTR
));
1987 if(!NT_SUCCESS(Status
))
1989 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1996 DPRINT("Leave NtUserSendMessageTimeout, ret=%i\n",_ret_
);
2002 NtUserSendMessage( HWND Wnd
,
2006 PNTUSERSENDMESSAGEINFO UnsafeInfo
)
2008 DECLARE_RETURN(BOOL
);
2010 DPRINT("Enter NtUserSendMessage\n");
2011 UserEnterExclusive();
2013 RETURN(co_IntDoSendMessage(Wnd
, Msg
, wParam
, lParam
, NULL
, UnsafeInfo
));
2016 DPRINT("Leave NtUserSendMessage, ret=%i\n",_ret_
);
2023 NtUserWaitMessage(VOID
)
2025 DECLARE_RETURN(BOOL
);
2027 DPRINT("EnterNtUserWaitMessage\n");
2028 UserEnterExclusive();
2030 RETURN(co_IntWaitMessage(NULL
, 0, 0));
2033 DPRINT("Leave NtUserWaitMessage, ret=%i\n",_ret_
);
2040 NtUserGetMessage( PNTUSERGETMESSAGEINFO UnsafeInfo
,
2045 * FUNCTION: Get a message from the calling thread's message queue.
2047 * UnsafeMsg - Pointer to the structure which receives the returned message.
2048 * Wnd - Window whose messages are to be retrieved.
2049 * MsgFilterMin - Integer value of the lowest message value to be
2051 * MsgFilterMax - Integer value of the highest message value to be
2056 NTUSERGETMESSAGEINFO Info
;
2058 /* FIXME: if initialization is removed, gcc complains that this may be used before initialization. Please review */
2060 PMSGMEMORY MsgMemoryEntry
;
2064 DECLARE_RETURN(BOOL
);
2065 // USER_REFERENCE_ENTRY Ref;
2067 DPRINT("Enter NtUserGetMessage\n");
2068 UserEnterExclusive();
2070 /* Validate input */
2071 if (hWnd
&& !(Window
= UserGetWindowObject(hWnd
)))
2076 // if (Window) UserRefObjectCo(Window, &Ref);
2078 if (MsgFilterMax
< MsgFilterMin
)
2086 GotMessage
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
);
2090 /* See if this message type is present in the table */
2091 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
2092 if (NULL
== MsgMemoryEntry
)
2094 /* Not present, no copying needed */
2095 Info
.LParamSize
= 0;
2099 /* Determine required size */
2100 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
2102 /* Allocate required amount of user-mode memory */
2103 Info
.LParamSize
= Size
;
2105 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
2106 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
2108 if (! NT_SUCCESS(Status
))
2110 SetLastNtError(Status
);
2113 /* Transfer lParam data to user-mode mem */
2114 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
2115 if (! NT_SUCCESS(Status
))
2117 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
2118 &Info
.LParamSize
, MEM_DECOMMIT
);
2119 SetLastNtError(Status
);
2122 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
2124 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
2125 if (! NT_SUCCESS(Status
))
2127 SetLastNtError(Status
);
2131 else if (! co_IntWaitMessage(Window
, MsgFilterMin
, MsgFilterMax
))
2136 while (! GotMessage
);
2138 RETURN( WM_QUIT
!= Info
.Msg
.message
);
2141 // if (Window) UserDerefObjectCo(Window);
2143 DPRINT("Leave NtUserGetMessage\n");
2159 DECLARE_RETURN(BOOL
);
2161 DPRINT("Enter NtUserGetMessage\n");
2162 UserEnterExclusive();
2164 if ( (MsgFilterMin
|MsgFilterMax
) & ~WM_MAXIMUM
)
2166 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2170 RtlZeroMemory(&Msg
, sizeof(MSG
));
2172 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, PM_REMOVE
, TRUE
);
2178 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
2179 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
2181 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2183 SetLastNtError(_SEH2_GetExceptionCode());
2191 DPRINT("Leave NtUserGetMessage\n");
2197 NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo
,
2205 NTUSERGETMESSAGEINFO Info
;
2207 PMSGMEMORY MsgMemoryEntry
;
2211 DECLARE_RETURN(BOOL
);
2213 DPRINT("Enter NtUserPeekMessage\n");
2214 UserEnterExclusive();
2216 if (hWnd
== (HWND
)-1 || hWnd
== (HWND
)0x0000FFFF || hWnd
== (HWND
)0xFFFFFFFF)
2219 /* Validate input */
2220 if (hWnd
&& hWnd
!= (HWND
)1)
2222 if (!(Window
= UserGetWindowObject(hWnd
)))
2229 Window
= (PWND
)hWnd
;
2232 if (MsgFilterMax
< MsgFilterMin
)
2238 Present
= co_IntPeekMessage(&Msg
, Window
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
);
2243 /* See if this message type is present in the table */
2244 MsgMemoryEntry
= FindMsgMemory(Info
.Msg
.message
);
2245 if (NULL
== MsgMemoryEntry
)
2247 /* Not present, no copying needed */
2248 Info
.LParamSize
= 0;
2252 /* Determine required size */
2253 Size
= MsgMemorySize(MsgMemoryEntry
, Info
.Msg
.wParam
,
2255 /* Allocate required amount of user-mode memory */
2256 Info
.LParamSize
= Size
;
2258 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem
, 0,
2259 &Info
.LParamSize
, MEM_COMMIT
, PAGE_READWRITE
);
2260 if (! NT_SUCCESS(Status
))
2262 SetLastNtError(Status
);
2265 /* Transfer lParam data to user-mode mem */
2266 Status
= MmCopyToCaller(UserMem
, (PVOID
) Info
.Msg
.lParam
, Size
);
2267 if (! NT_SUCCESS(Status
))
2269 ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID
*) &UserMem
,
2270 &Info
.LParamSize
, MEM_RELEASE
);
2271 SetLastNtError(Status
);
2274 Info
.Msg
.lParam
= (LPARAM
) UserMem
;
2276 Status
= MmCopyToCaller(UnsafeInfo
, &Info
, sizeof(NTUSERGETMESSAGEINFO
));
2277 if (! NT_SUCCESS(Status
))
2279 SetLastNtError(Status
);
2287 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2303 DECLARE_RETURN(BOOL
);
2305 DPRINT("Enter NtUserPeekMessage\n");
2306 UserEnterExclusive();
2308 if ( RemoveMsg
& PM_BADMSGFLAGS
)
2310 SetLastWin32Error(ERROR_INVALID_FLAGS
);
2314 RtlZeroMemory(&Msg
, sizeof(MSG
));
2316 Ret
= co_IntGetPeekMessage(&Msg
, hWnd
, MsgFilterMin
, MsgFilterMax
, RemoveMsg
, FALSE
);
2322 ProbeForWrite(pMsg
, sizeof(MSG
), 1);
2323 RtlCopyMemory(pMsg
, &Msg
, sizeof(MSG
));
2325 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2327 SetLastNtError(_SEH2_GetExceptionCode());
2335 DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_
);
2342 NtUserCallMsgFilter(
2346 BOOL BadChk
= FALSE
, Ret
= FALSE
;
2348 DECLARE_RETURN(BOOL
);
2350 DPRINT("Enter NtUserCallMsgFilter\n");
2351 UserEnterExclusive();
2356 ProbeForRead((PVOID
)lpmsg
,
2359 RtlCopyMemory( &Msg
,
2363 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2372 if (BadChk
) RETURN( FALSE
);
2374 if ( co_HOOK_CallHooks( WH_SYSMSGFILTER
, code
, 0, (LPARAM
)&Msg
))
2380 Ret
= co_HOOK_CallHooks( WH_MSGFILTER
, code
, 0, (LPARAM
)&Msg
);
2385 ProbeForWrite((PVOID
)lpmsg
,
2388 RtlCopyMemory((PVOID
)lpmsg
,
2392 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2397 if (BadChk
) RETURN( FALSE
);
2401 DPRINT("Leave NtUserCallMsgFilter. ret=%i\n", _ret_
);
2407 NtUserDispatchMessage(PMSG UnsafeMsgInfo
)
2413 UserEnterExclusive();
2416 ProbeForRead(UnsafeMsgInfo
, sizeof(MSG
), 1);
2417 RtlCopyMemory(&SafeMsg
, UnsafeMsgInfo
, sizeof(MSG
));
2419 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2421 SetLastNtError(_SEH2_GetExceptionCode());
2426 if (!Hit
) Res
= IntDispatchMessage(&SafeMsg
);
2434 NtUserTranslateMessage(LPMSG lpMsg
,
2439 DECLARE_RETURN(BOOL
);
2441 DPRINT("Enter NtUserTranslateMessage\n");
2442 UserEnterExclusive();
2444 Status
= MmCopyFromCaller(&SafeMsg
, lpMsg
, sizeof(MSG
));
2445 if(!NT_SUCCESS(Status
))
2447 SetLastNtError(Status
);
2451 RETURN( IntTranslateKbdMessage(&SafeMsg
, flags
));
2454 DPRINT("Leave NtUserTranslateMessage: ret=%i\n",_ret_
);
2465 ULONG_PTR ResultInfo
,
2466 DWORD dwType
, // fnID?
2469 LRESULT lResult
= 0;
2471 BOOL BadChk
= FALSE
;
2473 USER_REFERENCE_ENTRY Ref
;
2475 UserEnterExclusive();
2477 /* Validate input */
2478 if (hWnd
&& (hWnd
!= INVALID_HANDLE_VALUE
) && !(Window
= UserGetWindowObject(hWnd
)))
2485 case FNID_DEFWINDOWPROC
:
2486 UserRefObjectCo(Window
, &Ref
);
2487 lResult
= IntDefWindowProc(Window
, Msg
, wParam
, lParam
, Ansi
);
2489 UserDerefObjectCo(Window
);
2491 case FNID_SENDNOTIFYMESSAGE
:
2492 Ret
= UserSendNotifyMessage(hWnd
, Msg
, wParam
, lParam
);
2494 case FNID_BROADCASTSYSTEMMESSAGE
:
2497 DWORD_PTR RetVal
= 0;
2503 ProbeForWrite((PVOID
)ResultInfo
,
2504 sizeof(BROADCASTPARM
),
2506 RtlCopyMemory(&parm
, (PVOID
)ResultInfo
, sizeof(BROADCASTPARM
));
2508 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2518 if ( parm
.recipients
& BSM_ALLDESKTOPS
||
2519 parm
.recipients
== BSM_ALLCOMPONENTS
)
2522 else if (parm
.recipients
& BSM_APPLICATIONS
)
2524 if (parm
.flags
& BSF_QUERY
)
2526 if (parm
.flags
& BSF_FORCEIFHUNG
|| parm
.flags
& BSF_NOHANG
)
2528 co_IntSendMessageTimeout( HWND_BROADCAST
,
2536 else if (parm
.flags
& BSF_NOTIMEOUTIFNOTHUNG
)
2538 co_IntSendMessageTimeout( HWND_BROADCAST
,
2542 SMTO_NOTIMEOUTIFNOTHUNG
,
2548 co_IntSendMessageTimeout( HWND_BROADCAST
,
2557 else if (parm
.flags
& BSF_POSTMESSAGE
)
2559 Ret
= UserPostMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2561 else if ( parm
.flags
& BSF_SENDNOTIFYMESSAGE
)
2563 Ret
= UserSendNotifyMessage(HWND_BROADCAST
, Msg
, wParam
, lParam
);
2568 case FNID_SENDMESSAGECALLBACK
:
2570 PCALL_BACK_INFO CallBackInfo
= (PCALL_BACK_INFO
)ResultInfo
;
2576 if (!co_IntSendMessageWithCallBack(hWnd
, Msg
, wParam
, lParam
,
2577 CallBackInfo
->CallBack
, CallBackInfo
->Context
, &uResult
))
2579 DPRINT1("Callback failure!\n");
2583 // CallNextHook bypass.
2584 case FNID_CALLWNDPROC
:
2585 case FNID_CALLWNDPROCRET
:
2587 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
2588 PHOOK NextObj
, Hook
= ClientInfo
->phkCurrent
;
2590 if (!ClientInfo
|| !Hook
) break;
2592 UserReferenceObject(Hook
);
2594 if (Hook
->Thread
&& (Hook
->Thread
!= PsGetCurrentThread()))
2596 UserDereferenceObject(Hook
);
2600 NextObj
= IntGetNextHook(Hook
);
2601 ClientInfo
->phkCurrent
= NextObj
;
2603 if ( Hook
->HookId
== WH_CALLWNDPROC
)
2608 CWP
.wParam
= wParam
;
2609 CWP
.lParam
= lParam
;
2610 DPRINT("WH_CALLWNDPROC: Hook %x NextHook %x\n", Hook
, NextObj
);
2612 lResult
= co_IntCallHookProc( Hook
->HookId
,
2614 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2625 CWPR
.wParam
= wParam
;
2626 CWPR
.lParam
= lParam
;
2627 CWPR
.lResult
= ClientInfo
->dwHookData
;
2629 lResult
= co_IntCallHookProc( Hook
->HookId
,
2631 ((ClientInfo
->CI_flags
& CI_CURTHPRHOOK
) ? 1 : 0),
2637 UserDereferenceObject(Hook
);
2638 lResult
= (LRESULT
) NextObj
;
2645 case FNID_DEFWINDOWPROC
:
2646 case FNID_CALLWNDPROC
:
2647 case FNID_CALLWNDPROCRET
:
2652 ProbeForWrite((PVOID
)ResultInfo
, sizeof(LRESULT
), 1);
2653 RtlCopyMemory((PVOID
)ResultInfo
, &lResult
, sizeof(LRESULT
));
2655 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2668 return BadChk
? FALSE
: Ret
;
2671 #define INFINITE 0xFFFFFFFF
2672 #define WAIT_FAILED ((DWORD)0xFFFFFFFF)
2676 NtUserWaitForInputIdle(
2678 IN DWORD dwMilliseconds
,
2682 PPROCESSINFO W32Process
;
2685 LARGE_INTEGER Timeout
;
2686 ULONGLONG StartTime
, Run
, Elapsed
= 0;
2688 UserEnterExclusive();
2690 Status
= ObReferenceObjectByHandle(hProcess
,
2691 PROCESS_QUERY_INFORMATION
,
2697 if (!NT_SUCCESS(Status
))
2700 SetLastNtError(Status
);
2704 W32Process
= (PPROCESSINFO
)Process
->Win32Process
;
2707 ObDereferenceObject(Process
);
2709 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2713 EngCreateEvent((PEVENT
*)&W32Process
->InputIdleEvent
);
2715 Handles
[0] = Process
;
2716 Handles
[1] = W32Process
->InputIdleEvent
;
2720 ObDereferenceObject(Process
);
2722 return STATUS_SUCCESS
; /* no event to wait on */
2725 StartTime
= EngGetTickCount();
2727 Run
= dwMilliseconds
;
2729 DPRINT("WFII: waiting for %p\n", Handles
[1] );
2732 Timeout
.QuadPart
= Run
- Elapsed
;
2734 Status
= KeWaitForMultipleObjects( 2,
2740 dwMilliseconds
== INFINITE
? NULL
: &Timeout
,
2742 UserEnterExclusive();
2744 if (!NT_SUCCESS(Status
))
2746 SetLastNtError(Status
);
2747 Status
= WAIT_FAILED
;
2754 Status
= WAIT_FAILED
;
2760 co_IntPeekMessage( &Msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2764 case STATUS_USER_APC
:
2765 case STATUS_ALERTED
:
2766 case STATUS_TIMEOUT
:
2767 DPRINT1("WFII: timeout\n");
2768 Status
= STATUS_TIMEOUT
;
2772 DPRINT1("WFII: finished\n");
2773 Status
= STATUS_SUCCESS
;
2777 if (dwMilliseconds
!= INFINITE
)
2779 Elapsed
= EngGetTickCount() - StartTime
;
2782 Status
= STATUS_TIMEOUT
;
2789 if (W32Process
->InputIdleEvent
)
2791 EngFreeMem((PVOID
)W32Process
->InputIdleEvent
);
2792 W32Process
->InputIdleEvent
= NULL
;
2794 ObDereferenceObject(Process
);