ReactOS 0.4.17-dev-117-g313be0c
misc.c File Reference
#include <win32k.h>
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (UserMisc)
 
int __cdecl _scwprintf (const wchar_t *format,...)
 
PTHREADINFO FASTCALL IntTID2PTI (HANDLE id)
 
DWORD FASTCALL UserGetLanguageToggle (_In_ PCWSTR pszType, _In_ DWORD dwDefaultValue)
 
USHORT FASTCALL UserGetLanguageID (VOID)
 
HBRUSH FASTCALL GetControlColor (PWND pwndParent, PWND pwnd, HDC hdc, UINT CtlMsg)
 
HBRUSH FASTCALL GetControlBrush (PWND pwnd, HDC hdc, UINT ctlType)
 
HBRUSH APIENTRY NtUserGetControlBrush (HWND hwnd, HDC hdc, UINT ctlType)
 
HBRUSH APIENTRY NtUserGetControlColor (HWND hwndParent, HWND hwnd, HDC hdc, UINT CtlMsg)
 
DWORD_PTR APIENTRY NtUserGetThreadState (DWORD Routine)
 
DWORD APIENTRY NtUserSetThreadState (DWORD Set, DWORD Flags)
 
UINT APIENTRY NtUserGetDoubleClickTime (VOID)
 
BOOL APIENTRY NtUserGetGUIThreadInfo (DWORD idThread, LPGUITHREADINFO lpgui)
 
DWORD APIENTRY NtUserGetGuiResources (HANDLE hProcess, DWORD uiFlags)
 
VOID FASTCALL IntSetWindowState (PWND pWnd, UINT Flag)
 
VOID FASTCALL IntClearWindowState (PWND pWnd, UINT Flag)
 
NTSTATUS FASTCALL IntSafeCopyUnicodeString (PUNICODE_STRING Dest, PUNICODE_STRING Source)
 
NTSTATUS FASTCALL IntSafeCopyUnicodeStringTerminateNULL (PUNICODE_STRING Dest, PUNICODE_STRING Source)
 
void UserDbgAssertThreadInfo (BOOL showCaller)
 
void NTAPI UserDbgPreServiceHook (ULONG ulSyscallId, PULONG_PTR pulArguments)
 
ULONG_PTR NTAPI UserDbgPostServiceHook (ULONG ulSyscallId, ULONG_PTR ulResult)
 
PPROCESSINFO GetW32ProcessInfo (VOID)
 
PTHREADINFO GetW32ThreadInfo (VOID)
 
NTSTATUS GetProcessLuid (IN PETHREAD Thread OPTIONAL, IN PEPROCESS Process OPTIONAL, OUT PLUID Luid)
 

Function Documentation

◆ _scwprintf()

int __cdecl _scwprintf ( const wchar_t format,
  ... 
)

Definition at line 21 of file misc.c.

24{
25 int len;
27
30 va_end(args);
31
32 return len;
33}
_ACRTIMP int __cdecl _vscwprintf(const wchar_t *, va_list)
Definition: wcs.c:1782
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
char * va_list
Definition: vadefs.h:50
GLenum GLsizei len
Definition: glext.h:6722
#define args
Definition: format.c:66
Definition: match.c:390
Definition: format.c:58

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( UserMisc  )

◆ GetControlBrush()

HBRUSH FASTCALL GetControlBrush ( PWND  pwnd,
HDC  hdc,
UINT  ctlType 
)

Definition at line 179 of file misc.c.

183{
184 PWND pwndParent = IntGetParent(pwnd);
185 return GetControlColor( pwndParent, pwnd, hdc, ctlType);
186}
HDC hdc
Definition: main.c:9
Definition: ntuser.h:694
HBRUSH FASTCALL GetControlColor(PWND pwndParent, PWND pwnd, HDC hdc, UINT CtlMsg)
Definition: misc.c:153
PWND FASTCALL IntGetParent(PWND Wnd)
Definition: window.c:205

Referenced by EDIT_NotifyCtlColor(), IntDrawScrollInterior(), NtUserGetControlBrush(), and STATIC_SendWmCtlColorStatic().

◆ GetControlColor()

HBRUSH FASTCALL GetControlColor ( PWND  pwndParent,
PWND  pwnd,
HDC  hdc,
UINT  CtlMsg 
)

Definition at line 153 of file misc.c.

158{
159 HBRUSH hBrush;
160
161 if (!pwndParent) pwndParent = pwnd;
162
163 if ( pwndParent->head.pti->ppi != PsGetCurrentProcessWin32Process())
164 {
165 return (HBRUSH)IntDefWindowProc( pwndParent, CtlMsg, (WPARAM)hdc, (LPARAM)UserHMGetHandle(pwnd), FALSE);
166 }
167
168 hBrush = (HBRUSH)co_IntSendMessage( UserHMGetHandle(pwndParent), CtlMsg, (WPARAM)hdc, (LPARAM)UserHMGetHandle(pwnd));
169
170 if (!hBrush || !GreIsHandleValid(hBrush))
171 {
172 hBrush = (HBRUSH)IntDefWindowProc( pwndParent, CtlMsg, (WPARAM)hdc, (LPARAM)UserHMGetHandle(pwnd), FALSE);
173 }
174 return hBrush;
175}
#define FALSE
Definition: types.h:117
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
LONG_PTR LPARAM
Definition: minwindef.h:175
UINT_PTR WPARAM
Definition: minwindef.h:174
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
LRESULT FASTCALL IntDefWindowProc(PWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam, BOOL Ansi)
Definition: defwnd.c:633
THRDESKHEAD head
Definition: ntuser.h:695
BOOL NTAPI GreIsHandleValid(HGDIOBJ hobj)
Definition: gdiobj.c:1153
LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1495

Referenced by ButtonWndProc_common(), CB_Paint(), COMBO_PrepareColors(), DEFDLG_Proc(), GB_Paint(), GetControlBrush(), IntFillWindow(), LISTBOX_Paint(), LISTBOX_RepaintItem(), ListBoxWndProc_common(), NtUserGetControlColor(), OB_Paint(), PB_Paint(), and UB_Paint().

◆ GetProcessLuid()

NTSTATUS GetProcessLuid ( IN PETHREAD Thread  OPTIONAL,
IN PEPROCESS Process  OPTIONAL,
OUT PLUID  Luid 
)

Definition at line 814 of file misc.c.

818{
823
824 if (Thread && Process)
826
827 /* If nothing has been specified, use the current thread */
828 if (!Thread && !Process)
830
831 if (Thread)
832 {
833 /* Use a thread token */
834 ASSERT(!Process);
836 &CopyOnOpen,
839
840 /* If we don't have a thread token, use a process token */
841 if (!Token)
843 }
844 if (!Token && Process)
845 {
846 /* Use a process token */
848
849 /* If we don't have a token, fail */
850 if (!Token)
851 return STATUS_NO_TOKEN;
852 }
853 ASSERT(Token);
854
855 /* Query the LUID */
857
858 /* Get rid of the token and return */
860 return Status;
861}
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
PEPROCESS __stdcall PsGetThreadProcess(_In_ PETHREAD Thread)
#define NULL
Definition: types.h:112
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
Status
Definition: gdiplustypes.h:25
enum _SECURITY_IMPERSONATION_LEVEL SECURITY_IMPERSONATION_LEVEL
#define ASSERT(a)
Definition: mode.c:44
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ BOOLEAN EffectiveOnly
Definition: sefuncs.h:410
PACCESS_TOKEN NTAPI PsReferencePrimaryToken(PEPROCESS Process)
Definition: security.c:440
PACCESS_TOKEN NTAPI PsReferenceImpersonationToken(IN PETHREAD Thread, OUT PBOOLEAN CopyOnOpen, OUT PBOOLEAN EffectiveOnly, OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
Definition: security.c:871
NTSTATUS NTAPI SeQueryAuthenticationIdToken(_In_ PACCESS_TOKEN Token, _Out_ PLUID LogonId)
Queries the authentication ID of an access token.
Definition: token.c:2037
#define STATUS_NO_TOKEN
Definition: ntstatus.h:454
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define ObDereferenceObject
Definition: obfuncs.h:203
_Out_ PBOOLEAN CopyOnOpen
Definition: psfuncs.h:155
_Out_ PBOOLEAN _Out_ PBOOLEAN _Out_ PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
Definition: psfuncs.h:157

Referenced by BuildUserModeWindowStationName(), IntResolveDesktop(), UserEndShutdown(), and UserInitiateShutdown().

◆ GetW32ProcessInfo()

◆ GetW32ThreadInfo()

PTHREADINFO GetW32ThreadInfo ( VOID  )

Definition at line 806 of file misc.c.

807{
810}
#define TRUE
Definition: types.h:120
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
void UserDbgAssertThreadInfo(BOOL showCaller)
Definition: misc.c:733

Referenced by NtUserGetThreadState().

◆ IntClearWindowState()

VOID FASTCALL IntClearWindowState ( PWND  pWnd,
UINT  Flag 
)

Definition at line 617 of file misc.c.

618{
619 UINT bit;
620 if (gptiCurrent->ppi != pWnd->head.pti->ppi) return;
621 bit = 1 << LOWORD(Flag);
622 TRACE("CWS %x\n",bit);
623 switch(HIWORD(Flag))
624 {
625 case 0:
626 pWnd->state &= ~bit;
627 break;
628 case 1:
629 pWnd->state2 &= ~bit;
630 break;
631 case 2:
632 pWnd->ExStyle2 &= ~bit;
633 break;
634 }
635}
unsigned int UINT
Definition: ndis.h:50
PTHREADINFO gptiCurrent
Definition: ntuser.c:15
#define LOWORD(l)
Definition: pedump.c:82
#define TRACE(s)
Definition: solgame.cpp:4
Definition: xml2sdb.h:97
PPROCESSINFO ppi
Definition: win32.h:88
DWORD ExStyle2
Definition: ntuser.h:745
DWORD state2
Definition: ntuser.h:702
DWORD state
Definition: ntuser.h:701
#define HIWORD(l)
Definition: typedefs.h:247

Referenced by NtUserCallHwndParam().

◆ IntSafeCopyUnicodeString()

NTSTATUS FASTCALL IntSafeCopyUnicodeString ( PUNICODE_STRING  Dest,
PUNICODE_STRING  Source 
)

Definition at line 638 of file misc.c.

640{
642 PWSTR Src;
643
645 if(!NT_SUCCESS(Status))
646 {
647 return Status;
648 }
649
650 if(Dest->Length > 0x4000)
651 {
652 return STATUS_UNSUCCESSFUL;
653 }
654
655 Src = Dest->Buffer;
656 Dest->Buffer = NULL;
657 Dest->MaximumLength = Dest->Length;
658
659 if(Dest->Length > 0 && Src)
660 {
662 if(!Dest->Buffer)
663 {
664 return STATUS_NO_MEMORY;
665 }
666
667 Status = MmCopyFromCaller(Dest->Buffer, Src, Dest->Length);
668 if(!NT_SUCCESS(Status))
669 {
671 Dest->Buffer = NULL;
672 return Status;
673 }
674
675
676 return STATUS_SUCCESS;
677 }
678
679 /* String is empty */
680 return STATUS_SUCCESS;
681}
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
#define TAG_STRING
Definition: oslist.h:22
#define MmCopyFromCaller
Definition: polytest.cpp:29
#define STATUS_SUCCESS
Definition: shellext.h:65
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

◆ IntSafeCopyUnicodeStringTerminateNULL()

NTSTATUS FASTCALL IntSafeCopyUnicodeStringTerminateNULL ( PUNICODE_STRING  Dest,
PUNICODE_STRING  Source 
)

Definition at line 684 of file misc.c.

686{
688 PWSTR Src;
689
691 if(!NT_SUCCESS(Status))
692 {
693 return Status;
694 }
695
696 if(Dest->Length > 0x4000)
697 {
698 return STATUS_UNSUCCESSFUL;
699 }
700
701 Src = Dest->Buffer;
702 Dest->Buffer = NULL;
703 Dest->MaximumLength = 0;
704
705 if(Dest->Length > 0 && Src)
706 {
707 Dest->MaximumLength = Dest->Length + sizeof(WCHAR);
709 if(!Dest->Buffer)
710 {
711 return STATUS_NO_MEMORY;
712 }
713
714 Status = MmCopyFromCaller(Dest->Buffer, Src, Dest->Length);
715 if(!NT_SUCCESS(Status))
716 {
718 Dest->Buffer = NULL;
719 return Status;
720 }
721
722 /* Make sure the string is null-terminated */
723 Src = (PWSTR)((PBYTE)Dest->Buffer + Dest->Length);
724 *Src = L'\0';
725
726 return STATUS_SUCCESS;
727 }
728
729 /* String is empty */
730 return STATUS_SUCCESS;
731}
#define L(x)
Definition: resources.c:13
BYTE * PBYTE
Definition: pedump.c:66
short WCHAR
Definition: pedump.c:58

Referenced by InitThreadCallback(), and NtUserRegisterWindowMessage().

◆ IntSetWindowState()

VOID FASTCALL IntSetWindowState ( PWND  pWnd,
UINT  Flag 
)

Definition at line 596 of file misc.c.

597{
598 UINT bit;
599 if (gptiCurrent->ppi != pWnd->head.pti->ppi) return;
600 bit = 1 << LOWORD(Flag);
601 TRACE("SWS %x\n",bit);
602 switch(HIWORD(Flag))
603 {
604 case 0:
605 pWnd->state |= bit;
606 break;
607 case 1:
608 pWnd->state2 |= bit;
609 break;
610 case 2:
611 pWnd->ExStyle2 |= bit;
612 break;
613 }
614}

Referenced by NtUserCallHwndParam().

◆ IntTID2PTI()

PTHREADINFO FASTCALL IntTID2PTI ( HANDLE  id)

Definition at line 41 of file misc.c.

42{
45 PTHREADINFO pti;
47 if (!NT_SUCCESS(Status))
48 {
49 return NULL;
50 }
52 {
54 return NULL;
55 }
57 if (!pti)
58 {
60 return NULL;
61 }
62 // Validate and verify!
64 {
65 if (pti->TIF_flags & TIF_INCLEANUP) pti = NULL;
66 if (pti && !(pti->TIF_flags & TIF_GUITHREADINITIALIZED)) pti = NULL;
67 if (PsGetThreadId(Thread) != id) pti = NULL;
68 }
70 {
71 pti = NULL;
72 }
75 return pti;
76}
#define TIF_INCLEANUP
Definition: ntuser.h:263
#define TIF_GUITHREADINITIALIZED
Definition: ntuser.h:287
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
HANDLE NTAPI PsGetThreadId(IN PETHREAD Thread)
Definition: thread.c:705
NTSTATUS NTAPI PsLookupThreadByThreadId(IN HANDLE ThreadId, OUT PETHREAD *Thread)
Definition: thread.c:643
PVOID NTAPI PsGetThreadWin32Thread(IN PETHREAD Thread)
Definition: thread.c:795
BOOLEAN NTAPI PsIsThreadTerminating(IN PETHREAD Thread)
Definition: thread.c:868
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
FLONG TIF_flags
Definition: win32.h:95

Referenced by NtUserAttachThreadInput(), NtUserBuildHimcList(), NtUserDisableThreadIme(), NtUserGetGUIThreadInfo(), NtUserGetThreadDesktop(), NtUserGetThreadState(), and NtUserSetWindowsHookEx().

◆ NtUserGetControlBrush()

HBRUSH APIENTRY NtUserGetControlBrush ( HWND  hwnd,
HDC  hdc,
UINT  ctlType 
)

Definition at line 190 of file misc.c.

194{
195 PWND pwnd;
196 HBRUSH hBrush = NULL;
197
199 if ( (pwnd = UserGetWindowObject(hwnd)) &&
200 ((ctlType - WM_CTLCOLORMSGBOX) < CTLCOLOR_MAX) &&
201 hdc )
202 {
203 hBrush = GetControlBrush(pwnd, hdc, ctlType);
204 }
205 UserLeave();
206 return hBrush;
207}
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:255
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:247
PWND FASTCALL UserGetWindowObject(HWND hWnd)
Definition: window.c:123
HBRUSH FASTCALL GetControlBrush(PWND pwnd, HDC hdc, UINT ctlType)
Definition: misc.c:179
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define WM_CTLCOLORMSGBOX
Definition: winuser.h:1794
#define CTLCOLOR_MAX
Definition: winuser.h:969

Referenced by GetControlBrush().

◆ NtUserGetControlColor()

HBRUSH APIENTRY NtUserGetControlColor ( HWND  hwndParent,
HWND  hwnd,
HDC  hdc,
UINT  CtlMsg 
)

Definition at line 214 of file misc.c.

219{
220 PWND pwnd, pwndParent = NULL;
221 HBRUSH hBrush = NULL;
222
224 if ( (pwnd = UserGetWindowObject(hwnd)) &&
225 ((CtlMsg - WM_CTLCOLORMSGBOX) < CTLCOLOR_MAX) &&
226 hdc )
227 {
228 if (hwndParent) pwndParent = UserGetWindowObject(hwndParent);
229 hBrush = GetControlColor( pwndParent, pwnd, hdc, CtlMsg);
230 }
231 UserLeave();
232 return hBrush;
233}
static HWND hwndParent
Definition: cryptui.c:300

Referenced by GetControlColor().

◆ NtUserGetDoubleClickTime()

UINT APIENTRY NtUserGetDoubleClickTime ( VOID  )

Definition at line 387 of file misc.c.

388{
389 UINT Result;
390
391 TRACE("Enter NtUserGetDoubleClickTime\n");
393
394 // FIXME: Check if this works on non-interactive winsta
396
397 TRACE("Leave NtUserGetDoubleClickTime, ret=%u\n", Result);
398 UserLeave();
399 return Result;
400}
VOID FASTCALL UserEnterShared(VOID)
Definition: ntuser.c:241
INT iDblClickTime
Definition: sysparams.h:90
SPIVALUES gspv
Definition: sysparams.c:17
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by GetDoubleClickTime().

◆ NtUserGetGuiResources()

DWORD APIENTRY NtUserGetGuiResources ( HANDLE  hProcess,
DWORD  uiFlags 
)

Definition at line 535 of file misc.c.

538{
540 PPROCESSINFO W32Process;
542 DWORD Ret = 0;
543
544 TRACE("Enter NtUserGetGuiResources\n");
546
551 (PVOID*)&Process,
552 NULL);
553
554 if(!NT_SUCCESS(Status))
555 {
557 goto Exit; // Return 0
558 }
559
560 W32Process = (PPROCESSINFO)Process->Win32Process;
561 if(!W32Process)
562 {
565 goto Exit; // Return 0
566 }
567
568 switch(uiFlags)
569 {
570 case GR_GDIOBJECTS:
571 {
572 Ret = (DWORD)W32Process->GDIHandleCount;
573 break;
574 }
575 case GR_USEROBJECTS:
576 {
577 Ret = (DWORD)W32Process->UserHandleCount;
578 break;
579 }
580 default:
581 {
583 break;
584 }
585 }
586
588
589Exit:
590 TRACE("Leave NtUserGetGuiResources, ret=%lu\n", Ret);
591 UserLeave();
592 return Ret;
593}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ExGetPreviousMode
Definition: ex.h:143
unsigned long DWORD
Definition: ntddk_ex.h:95
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:162
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
#define DWORD
Definition: nt_native.h:44
POBJECT_TYPE PsProcessType
Definition: process.c:20
struct _PROCESSINFO * PPROCESSINFO
Definition: ntwin32.h:5
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
static void Exit(void)
Definition: sock.c:1330
VOID FASTCALL SetLastNtError(_In_ NTSTATUS Status)
Definition: error.c:30
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:21

Referenced by GetGuiResources().

◆ NtUserGetGUIThreadInfo()

BOOL APIENTRY NtUserGetGUIThreadInfo ( DWORD  idThread,
LPGUITHREADINFO  lpgui 
)

Definition at line 404 of file misc.c.

407{
409 PTHRDCARETINFO CaretInfo;
410 GUITHREADINFO SafeGui;
412 PUSER_MESSAGE_QUEUE MsgQueue;
413 PTHREADINFO W32Thread, pti;
414 BOOL Ret = FALSE;
415
416 TRACE("Enter NtUserGetGUIThreadInfo\n");
418
419 Status = MmCopyFromCaller(&SafeGui, lpgui, sizeof(DWORD));
420 if(!NT_SUCCESS(Status))
421 {
423 goto Exit; // Return FALSE
424 }
425
426 if(SafeGui.cbSize != sizeof(GUITHREADINFO))
427 {
429 goto Exit; // Return FALSE
430 }
431
432 if (idThread)
433 {
435
436 // Validate Tread ID
437 W32Thread = IntTID2PTI(UlongToHandle(idThread));
438
439 if ( !W32Thread )
440 {
442 goto Exit; // Return FALSE
443 }
444
445 Desktop = W32Thread->rpdesk;
446
447 // Check Desktop and it must be the same as current.
448 if ( !Desktop || Desktop != pti->rpdesk )
449 {
451 goto Exit; // Return FALSE
452 }
453
454 if ( W32Thread->MessageQueue )
455 MsgQueue = W32Thread->MessageQueue;
456 else
457 {
458 MsgQueue = Desktop->ActiveMessageQueue;
459 }
460 }
461 else
462 { /* Get the foreground thread */
463 /* FIXME: Handle NULL queue properly? */
464 MsgQueue = IntGetFocusMessageQueue();
465 if(!MsgQueue)
466 {
468 goto Exit; // Return FALSE
469 }
470 }
471
472 CaretInfo = &MsgQueue->CaretInfo;
473
474 SafeGui.flags = (CaretInfo->Visible ? GUI_CARETBLINKING : 0);
475/*
476 if (W32Thread->pMenuState->pGlobalPopupMenu)
477 {
478 SafeGui.flags |= GUI_INMENUMODE;
479
480 if (W32Thread->pMenuState->pGlobalPopupMenu->spwndNotify)
481 SafeGui.hwndMenuOwner = UserHMGetHandle(W32Thread->pMenuState->pGlobalPopupMenu->spwndNotify);
482
483 if (W32Thread->pMenuState->pGlobalPopupMenu->fHasMenuBar)
484 {
485 if (W32Thread->pMenuState->pGlobalPopupMenu->fIsSysMenu)
486 {
487 SafeGui.flags |= GUI_SYSTEMMENUMODE;
488 }
489 }
490 else
491 {
492 SafeGui.flags |= GUI_POPUPMENUMODE;
493 }
494 }
495 */
496 SafeGui.hwndMenuOwner = MsgQueue->MenuOwner;
497
498 if (MsgQueue->MenuOwner)
499 SafeGui.flags |= GUI_INMENUMODE | MsgQueue->MenuState;
500
501 if (MsgQueue->MoveSize)
502 SafeGui.flags |= GUI_INMOVESIZE;
503
504 /* FIXME: Add flag GUI_16BITTASK */
505
506 SafeGui.hwndActive = MsgQueue->spwndActive ? UserHMGetHandle(MsgQueue->spwndActive) : 0;
507 SafeGui.hwndFocus = MsgQueue->spwndFocus ? UserHMGetHandle(MsgQueue->spwndFocus) : 0;
508 SafeGui.hwndCapture = MsgQueue->spwndCapture ? UserHMGetHandle(MsgQueue->spwndCapture) : 0;
509 SafeGui.hwndMoveSize = MsgQueue->MoveSize;
510 SafeGui.hwndCaret = CaretInfo->hWnd;
511
512 SafeGui.rcCaret.left = CaretInfo->Pos.x;
513 SafeGui.rcCaret.top = CaretInfo->Pos.y;
514 SafeGui.rcCaret.right = SafeGui.rcCaret.left + CaretInfo->Size.cx;
515 SafeGui.rcCaret.bottom = SafeGui.rcCaret.top + CaretInfo->Size.cy;
516
517 Status = MmCopyToCaller(lpgui, &SafeGui, sizeof(GUITHREADINFO));
518 if(!NT_SUCCESS(Status))
519 {
521 goto Exit; // Return FALSE
522 }
523
524 Ret = TRUE;
525
526Exit:
527 TRACE("Leave NtUserGetGUIThreadInfo, ret=%i\n", Ret);
528 UserLeave();
529 return Ret;
530}
#define UlongToHandle(ul)
Definition: basetsd.h:91
static CHAR Desktop[MAX_PATH]
Definition: dem.c:256
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
unsigned int BOOL
Definition: ntddk_ex.h:94
#define MmCopyToCaller(x, y, z)
Definition: mmcopy.h:19
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
struct _DESKTOP * rpdesk
Definition: win32.h:92
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:89
THRDCARETINFO CaretInfo
Definition: msgqueue.h:92
HWND hwndCaret
Definition: winable.h:77
HWND hwndFocus
Definition: winable.h:73
HWND hwndMenuOwner
Definition: winable.h:75
HWND hwndMoveSize
Definition: winable.h:76
DWORD cbSize
Definition: winable.h:70
HWND hwndCapture
Definition: winable.h:74
HWND hwndActive
Definition: winable.h:72
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
LONG right
Definition: windef.h:108
LONG bottom
Definition: windef.h:109
LONG top
Definition: windef.h:107
LONG left
Definition: windef.h:106
PUSER_MESSAGE_QUEUE FASTCALL IntGetFocusMessageQueue(VOID)
Definition: desktop.c:1324
PTHREADINFO FASTCALL IntTID2PTI(HANDLE id)
Definition: misc.c:41
#define GUI_INMENUMODE
Definition: winable.h:29
#define GUI_CARETBLINKING
Definition: winable.h:27
#define GUI_INMOVESIZE
Definition: winable.h:28

Referenced by GetActiveWindow(), GetCapture(), GetFocus(), and GetGUIThreadInfo().

◆ NtUserGetThreadState()

DWORD_PTR APIENTRY NtUserGetThreadState ( DWORD  Routine)

Definition at line 239 of file misc.c.

241{
242 DWORD_PTR ret = 0;
243 PTHREADINFO pti;
244
245 TRACE("Enter NtUserGetThreadState\n");
246 if (Routine != THREADSTATE_GETTHREADINFO)
247 {
249 }
250 else
251 {
253 }
254
256
257 switch (Routine)
258 {
260 ret = TRUE;
261 break;
264 break;
266 /* FIXME: Should use UserEnterShared */
268 break;
269 case THREADSTATE_PROGMANWINDOW: /* FIXME: Delete this HACK */
270 ret = (DWORD_PTR)GetW32ThreadInfo()->pDeskInfo->hProgmanWindow;
271 break;
272 case THREADSTATE_TASKMANWINDOW: /* FIXME: Delete this HACK */
273 ret = (DWORD_PTR)GetW32ThreadInfo()->pDeskInfo->hTaskManWindow;
274 break;
277 break;
279 {
282 TRACE("THREADSTATE_INSENDMESSAGE\n");
283
284 ret = ISMEX_NOSEND;
285 if (Message)
286 {
287 if (Message->ptiSender)
288 ret = ISMEX_SEND;
289 else
290 {
291 if (Message->CompletionCallback)
292 ret = ISMEX_CALLBACK;
293 else
294 ret = ISMEX_NOTIFY;
295 }
296 /* If ReplyMessage */
297 if (Message->QS_Flags & QS_SMRESULT) ret |= ISMEX_REPLIED;
298 }
299
300 break;
301 }
304 break;
305
307 pti->pcti->timeLastRead = EngGetTickCount32();
308 break;
309
312 break;
313
316 break;
318 ret = (DWORD_PTR) (GetW32ThreadInfo()->MessageQueue->CursorObject ?
319 UserHMGetHandle(GetW32ThreadInfo()->MessageQueue->CursorObject) : 0);
320 break;
323 break;
325 if (pti->spwndDefaultIme)
327 break;
329 if (pti->spDefaultImc)
331 break;
333 ret = pti->pcti->fsChangeBits;
334 break;
336 ret = pti->ppi->dwImeCompatFlags;
337 break;
339 ret = (ULONG_PTR)pti->hklPrev;
340 break;
343 break;
345 FIXME("stub\n");
346 break;
348 ret = (IntTID2PTI(UlongToHandle(pti->rpdesk->dwConsoleThreadId)) == pti);
349 break;
350 }
351
352 TRACE("Leave NtUserGetThreadState, ret=%lu\n", ret);
353 UserLeave();
354
355 return ret;
356}
#define FIXME(fmt,...)
Definition: precomp.h:53
static const WCHAR Message[]
Definition: register.c:74
return ret
Definition: mutex.c:146
#define ULONG_PTR
Definition: config.h:101
#define EngGetTickCount32()
Definition: eng.h:43
HWND FASTCALL IntGetThreadFocusWindow(VOID)
Definition: focus.c:43
PUSER_MESSAGE_QUEUE gpqForeground
Definition: focus.c:13
HWND APIENTRY IntGetCapture(VOID)
Definition: focus.c:1436
HWND FASTCALL UserGetActiveWindow(VOID)
Definition: focus.c:1426
@ THREADSTATE_GETCURSOR
Definition: ntuser.h:2495
@ THREADSTATE_DEFAULTIMEWINDOW
Definition: ntuser.h:2492
@ THREADSTATE_DEFAULTINPUTCONTEXT
Definition: ntuser.h:2493
@ THREADSTATE_CHECKCONIME
Definition: ntuser.h:2506
@ THREADSTATE_INSENDMESSAGE
Definition: ntuser.h:2499
@ THREADSTATE_GETTHREADINFO
Definition: ntuser.h:2507
@ THREADSTATE_CAPTUREWINDOW
Definition: ntuser.h:2491
@ THREADSTATE_TASKMANWINDOW
Definition: ntuser.h:2509
@ THREADSTATE_UNKNOWN_0x10
Definition: ntuser.h:2505
@ THREADSTATE_FOREGROUNDTHREAD
Definition: ntuser.h:2501
@ THREADSTATE_OLDKEYBOARDLAYOUT
Definition: ntuser.h:2503
@ THREADSTATE_GETINPUTSTATE
Definition: ntuser.h:2494
@ THREADSTATE_PROGMANWINDOW
Definition: ntuser.h:2508
@ THREADSTATE_ACTIVEWINDOW
Definition: ntuser.h:2490
@ THREADSTATE_GETMESSAGETIME
Definition: ntuser.h:2500
@ THREADSTATE_FOCUSWINDOW
Definition: ntuser.h:2489
@ THREADSTATE_GETMESSAGEEXTRAINFO
Definition: ntuser.h:2498
@ THREADSTATE_ISWINLOGON
Definition: ntuser.h:2504
@ THREADSTATE_UPTIMELASTREAD
Definition: ntuser.h:2497
@ THREADSTATE_CHANGEBITS
Definition: ntuser.h:2496
@ THREADSTATE_IMECOMPATFLAGS
Definition: ntuser.h:2502
LPARAM FASTCALL MsqGetMessageExtraInfo(VOID)
Definition: msgqueue.c:2467
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
struct _THREADINFO * PTHREADINFO
Definition: ntwin32.h:6
HANDLE gpidLogon
Definition: simplecall.c:15
DWORD dwImeCompatFlags
Definition: win32.h:277
struct _DESKTOPINFO * pDeskInfo
Definition: win32.h:93
struct tagIMC * spDefaultImc
Definition: win32.h:132
HKL hklPrev
Definition: win32.h:133
struct _CLIENTTHREADINFO * pcti
Definition: win32.h:91
struct _WND * spwndDefaultIme
Definition: win32.h:131
#define DWORD_PTR
Definition: treelist.c:76
uint32_t DWORD_PTR
Definition: typedefs.h:65
#define QS_SMRESULT
Definition: undocuser.h:96
DWORD APIENTRY IntGetQueueStatus(DWORD Changes)
Definition: message.c:2139
PTHREADINFO GetW32ThreadInfo(VOID)
Definition: misc.c:806
#define QS_KEY
Definition: winuser.h:885
#define QS_SENDMESSAGE
Definition: winuser.h:891
#define QS_TIMER
Definition: winuser.h:889
#define QS_MOUSEBUTTON
Definition: winuser.h:887
#define QS_INPUT
Definition: winuser.h:910
#define QS_POSTMESSAGE
Definition: winuser.h:888
#define QS_PAINT
Definition: winuser.h:890

Referenced by CheckThreadState(), DIALOG_CreateIndirect(), DoTest_BUTTON(), DoTest_EDIT(), GetActiveWindow(), GetCapture(), GetCursor(), GetFocus(), GetInputState(), GetMessageTime(), GetProgmanWindow(), GetTaskmanWindow(), GetW32ThreadInfo(), ImeWnd_OnImeSetContext(), Imm32CurrentPti(), Imm32ImeNonImeToggle(), Imm32InquireIme(), ImmCreateContext(), ImmDllInitialize(), ImmGetDefaultIMEWnd(), ImmGetSaveContext(), ImmLockClientImc(), ImmWINNLSEnableIME(), InSendMessage(), InSendMessageEx(), IsGUIThread(), NtUserxGetMessageExtraInfo(), and PeekMessageWorker().

◆ NtUserSetThreadState()

DWORD APIENTRY NtUserSetThreadState ( DWORD  Set,
DWORD  Flags 
)

Definition at line 360 of file misc.c.

363{
364 PTHREADINFO pti;
365 DWORD Ret = 0;
366 // Test the only flags user can change.
371 if (pti->MessageQueue)
372 {
373 Ret = pti->MessageQueue->QF_flags; // Get the queue flags.
374 if (Set)
375 pti->MessageQueue->QF_flags |= (Set&Flags); // Set the queue flags.
376 else
377 {
378 if (Flags) pti->MessageQueue->QF_flags &= ~Flags; // Clr the queue flags.
379 }
380 }
381 UserLeave();
382 return Ret;
383}
#define QF_DIALOGACTIVE
Definition: msgqueue.h:106
#define QF_TABSWITCHING
Definition: msgqueue.h:101
#define QF_FMENUSTATUSBREAK
Definition: msgqueue.h:96
#define QF_FMENUSTATUS
Definition: msgqueue.h:97
#define QF_FF10STATUS
Definition: msgqueue.h:98
static BOOL Set
Definition: pageheap.c:10
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by DEFDLG_Proc().

◆ UserDbgAssertThreadInfo()

void UserDbgAssertThreadInfo ( BOOL  showCaller)

Definition at line 733 of file misc.c.

734{
735 PTEB Teb;
736 PPROCESSINFO ppi;
737 PCLIENTINFO pci;
738 PTHREADINFO pti;
739
742 Teb = NtCurrentTeb();
743 pci = GetWin32ClientInfo();
744
745 ASSERT(Teb);
746 ASSERT(pti);
747 ASSERT(pti->ppi == ppi);
748 ASSERT(pti->pClientInfo == pci);
749 ASSERT(Teb->Win32ThreadInfo == pti);
750 ASSERT(pci->ppi == ppi);
751 ASSERT(pci->fsHooks == pti->fsHooks);
753 if (pti->pcti && pci->pDeskInfo)
754 ASSERT(pci->pClientThreadInfo == (PVOID)((ULONG_PTR)pti->pcti - pci->ulClientDelta));
755 if (pti->KeyboardLayout)
756 ASSERT(pci->hKL == pti->KeyboardLayout->hkl);
757 if(pti->rpdesk != NULL)
758 ASSERT(pti->pDeskInfo == pti->rpdesk->pDeskInfo);
759
760 /*too bad we still get this assertion*/
761
762 // Why? Not all flags are passed to the user and doing so could crash the system........
763
764 /* ASSERT(pci->dwTIFlags == pti->TIF_flags); */
765/* if(pci->dwTIFlags != pti->TIF_flags)
766 {
767 ERR("pci->dwTIFlags(0x%x) doesn't match pti->TIF_flags(0x%x)\n", pci->dwTIFlags, pti->TIF_flags);
768 if(showCaller)
769 {
770 DbgPrint("Caller:\n");
771 KeRosDumpStackFrames(NULL, 10);
772 }
773 pci->dwTIFlags = pti->TIF_flags;
774 }
775*/
776}
static __inline ULONG_PTR DesktopHeapGetUserDelta(VOID)
Definition: desktop.h:272
#define GetWin32ClientInfo()
Definition: ntuser.h:352
#define NtCurrentTeb
HKL hKL
Definition: ntuser.h:339
ULONG_PTR ulClientDelta
Definition: ntuser.h:326
ULONG fsHooks
Definition: ntuser.h:328
PCLIENTTHREADINFO pClientThreadInfo
Definition: ntuser.h:332
PDESKTOPINFO pDeskInfo
Definition: ntuser.h:325
struct _PROCESSINFO * ppi
Definition: ntuser.h:346
Definition: compat.h:836
PVOID Win32ThreadInfo
Definition: compat.h:846
ULONG fsHooks
Definition: win32.h:117
struct _CLIENTINFO * pClientInfo
Definition: win32.h:94
struct tagKL * KeyboardLayout
Definition: win32.h:90
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by GetW32ThreadInfo(), UserDbgPostServiceHook(), and UserDbgPreServiceHook().

◆ UserDbgPostServiceHook()

ULONG_PTR NTAPI UserDbgPostServiceHook ( ULONG  ulSyscallId,
ULONG_PTR  ulResult 
)

Definition at line 787 of file misc.c.

788{
789 /* Make sure that the first syscall is NtUserInitialize */
790 /* too bad this fails */
791 // ASSERT(gpepCSRSS);
792
794
795 return ulResult;
796}

◆ UserDbgPreServiceHook()

void NTAPI UserDbgPreServiceHook ( ULONG  ulSyscallId,
PULONG_PTR  pulArguments 
)

Definition at line 780 of file misc.c.

781{
783}

◆ UserGetLanguageID()

USHORT FASTCALL UserGetLanguageID ( VOID  )

Definition at line 104 of file misc.c.

105{
107 OBJECT_ATTRIBUTES ObAttr;
108// https://learn.microsoft.com/en-us/troubleshoot/windows-server/setup-upgrade-and-drivers/use-language-id-identify-language-pack
112 UNICODE_STRING Language;
113
114 RtlInitUnicodeString( &Language,
115 L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Nls\\Language");
116
118 &Language,
120 NULL,
121 NULL);
122
123 if ( NT_SUCCESS(ZwOpenKey(&KeyHandle, KEY_READ, &ObAttr)))
124 {
126 if ( pKeyInfo )
127 {
128 RtlInitUnicodeString(&Language, L"Default");
129
130 if ( NT_SUCCESS(ZwQueryValueKey( KeyHandle,
131 &Language,
133 pKeyInfo,
134 Size,
135 &Size)) )
136 {
137 RtlInitUnicodeString(&Language, (PWSTR)pKeyInfo->Data);
138 if (!NT_SUCCESS(RtlUnicodeStringToInteger(&Language, 16, &Ret)))
139 {
141 }
142 }
143 ExFreePoolWithTag(pKeyInfo, TAG_STRING);
144 }
146 }
147 TRACE("Language ID = %x\n",Ret);
148 return (USHORT) Ret;
149}
#define MAX_PATH
Definition: compat.h:34
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ KeyValuePartialInformation
Definition: nt_native.h:1185
#define KEY_READ
Definition: nt_native.h:1026
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
unsigned short USHORT
Definition: pedump.c:61
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define MAKELANGID(p, s)
Definition: nls.h:15
#define LANG_ENGLISH
Definition: nls.h:52
#define SUBLANG_DEFAULT
Definition: nls.h:168
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539

Referenced by InitializeGreCSRSS().

◆ UserGetLanguageToggle()

DWORD FASTCALL UserGetLanguageToggle ( _In_ PCWSTR  pszType,
_In_ DWORD  dwDefaultValue 
)
See also
https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-2000-server/cc976564%28v=technet.10%29

Definition at line 83 of file misc.c.

86{
88 DWORD dwValue = dwDefaultValue;
89 WCHAR szBuff[4];
90
91 Status = RegReadUserSetting(L"Keyboard Layout\\Toggle", pszType, REG_SZ, szBuff, sizeof(szBuff));
92 if (NT_SUCCESS(Status))
93 {
94 szBuff[RTL_NUMBER_OF(szBuff) - 1] = UNICODE_NULL;
95 dwValue = _wtoi(szBuff);
96 }
97
98 TRACE("%ls: %lu\n", pszType, dwValue);
99 return dwValue;
100}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
_ACRTIMP int __cdecl _wtoi(const wchar_t *)
Definition: wcs.c:2773
#define REG_SZ
Definition: layer.c:22
#define UNICODE_NULL

Referenced by SpiGetSet(), and SpiUpdatePerUserSystemParameters().