https://git.reactos.org/?p=reactos.git;a=commitdiff;h=41b87158ffe9be1a2fcbd…
commit 41b87158ffe9be1a2fcbdd164c4e6bc5988fcc0f
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Thu Jan 20 11:49:27 2022 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Thu Jan 20 11:49:27 2022 +0900
[NTUSER] Improve NtUserGetThreadState (#4300)
- Improve enum ThreadStateRoutines.
- Improve NtUserGetThreadState function.
- Improve CLIENTIMC structure.
- Improve imm32 code.
CORE-17732
---
dll/win32/imm32/ime.c | 5 ++---
dll/win32/imm32/imm.c | 12 ++++--------
win32ss/include/ntuser.h | 29 ++++++++++++++++++----------
win32ss/user/ntuser/misc.c | 47 ++++++++++++++++++++++++++++++++++------------
4 files changed, 60 insertions(+), 33 deletions(-)
diff --git a/dll/win32/imm32/ime.c b/dll/win32/imm32/ime.c
index 4866bd00f5f..853951b352b 100644
--- a/dll/win32/imm32/ime.c
+++ b/dll/win32/imm32/ime.c
@@ -49,7 +49,7 @@ BOOL APIENTRY Imm32InquireIme(PIMEDPI pImeDpi)
DWORD dwSysInfoFlags = 0;
LPIMEINFO pImeInfo = &pImeDpi->ImeInfo;
- if (NtUserGetThreadState(16))
+ if (NtUserGetThreadState(THREADSTATE_ISWINLOGON2))
dwSysInfoFlags |= IME_SYSINFO_WINLOGON;
if (IS_IME_HKL(pImeDpi->hKL))
@@ -633,9 +633,8 @@ HWND WINAPI ImmGetDefaultIMEWnd(HWND hWnd)
if (!Imm32IsImmMode())
return NULL;
- // FIXME: NtUserGetThreadState and enum ThreadStateRoutines are broken.
if (hWnd == NULL)
- return (HWND)NtUserGetThreadState(3);
+ return (HWND)NtUserGetThreadState(THREADSTATE_DEFAULTIMEWINDOW);
return (HWND)NtUserQueryWindow(hWnd, QUERY_WINDOW_DEFAULT_IME);
}
diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c
index e916d44480f..b965e0d3093 100644
--- a/dll/win32/imm32/imm.c
+++ b/dll/win32/imm32/imm.c
@@ -606,8 +606,7 @@ HIMC WINAPI ImmCreateContext(void)
RtlInitializeCriticalSection(&pClientImc->cs);
- // FIXME: NtUserGetThreadState and enum ThreadStateRoutines are broken.
- pClientImc->unknown = NtUserGetThreadState(13);
+ pClientImc->dwCompatFlags =
(DWORD)NtUserGetThreadState(THREADSTATE_IMECOMPATFLAGS);
return hIMC;
}
@@ -925,8 +924,7 @@ PCLIENTIMC WINAPI ImmLockClientImc(HIMC hImc)
RtlInitializeCriticalSection(&pClientImc->cs);
- // FIXME: NtUserGetThreadState and enum ThreadStateRoutines are broken.
- pClientImc->unknown = NtUserGetThreadState(13);
+ pClientImc->dwCompatFlags =
(DWORD)NtUserGetThreadState(THREADSTATE_IMECOMPATFLAGS);
if (!NtUserUpdateInputContext(hImc, UIC_CLIENTIMCDATA, (DWORD_PTR)pClientImc))
{
@@ -979,8 +977,7 @@ static HIMC APIENTRY Imm32GetContextEx(HWND hWnd, DWORD
dwContextFlags)
if (!hWnd)
{
- // FIXME: NtUserGetThreadState and enum ThreadStateRoutines are broken.
- hIMC = (HIMC)NtUserGetThreadState(4);
+ hIMC = (HIMC)NtUserGetThreadState(THREADSTATE_DEFAULTINPUTCONTEXT);
goto Quit;
}
@@ -1275,8 +1272,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID
lpReserved)
return TRUE;
hKL = GetKeyboardLayout(0);
- // FIXME: NtUserGetThreadState and enum ThreadStateRoutines are broken.
- hIMC = (HIMC)NtUserGetThreadState(4);
+ hIMC = (HIMC)NtUserGetThreadState(THREADSTATE_DEFAULTINPUTCONTEXT);
Imm32CleanupContext(hIMC, hKL, TRUE);
break;
diff --git a/win32ss/include/ntuser.h b/win32ss/include/ntuser.h
index e6db897fa4b..dab6b267781 100644
--- a/win32ss/include/ntuser.h
+++ b/win32ss/include/ntuser.h
@@ -1294,7 +1294,7 @@ typedef struct tagCLIENTIMC
HANDLE hInputContext; /* LocalAlloc'ed LHND */
LONG cLockObj;
DWORD dwFlags;
- DWORD unknown;
+ DWORD dwCompatFlags;
RTL_CRITICAL_SECTION cs;
UINT uCodePage;
HKL hKL;
@@ -1305,6 +1305,7 @@ typedef struct tagCLIENTIMC
C_ASSERT(offsetof(CLIENTIMC, hInputContext) == 0x0);
C_ASSERT(offsetof(CLIENTIMC, cLockObj) == 0x4);
C_ASSERT(offsetof(CLIENTIMC, dwFlags) == 0x8);
+C_ASSERT(offsetof(CLIENTIMC, dwCompatFlags) == 0xc);
C_ASSERT(offsetof(CLIENTIMC, cs) == 0x10);
C_ASSERT(offsetof(CLIENTIMC, uCodePage) == 0x28);
C_ASSERT(offsetof(CLIENTIMC, hKL) == 0x2c);
@@ -2550,20 +2551,28 @@ NtUserGetThreadDesktop(
enum ThreadStateRoutines
{
- THREADSTATE_GETTHREADINFO,
- THREADSTATE_INSENDMESSAGE,
- THREADSTATE_FOCUSWINDOW,
+ THREADSTATE_FOCUSWINDOW = 0,
THREADSTATE_ACTIVEWINDOW,
THREADSTATE_CAPTUREWINDOW,
- THREADSTATE_PROGMANWINDOW,
- THREADSTATE_TASKMANWINDOW,
- THREADSTATE_GETMESSAGETIME,
+ THREADSTATE_DEFAULTIMEWINDOW,
+ THREADSTATE_DEFAULTINPUTCONTEXT,
THREADSTATE_GETINPUTSTATE,
- THREADSTATE_UPTIMELASTREAD,
- THREADSTATE_FOREGROUNDTHREAD,
THREADSTATE_GETCURSOR,
+ THREADSTATE_CHANGEBITS,
+ THREADSTATE_UPTIMELASTREAD,
THREADSTATE_GETMESSAGEEXTRAINFO,
- THREADSTATE_UNKNOWN13
+ THREADSTATE_INSENDMESSAGE,
+ THREADSTATE_GETMESSAGETIME,
+ THREADSTATE_FOREGROUNDTHREAD,
+ THREADSTATE_IMECOMPATFLAGS,
+ THREADSTATE_OLDKEYBOARDLAYOUT,
+ THREADSTATE_ISWINLOGON,
+ THREADSTATE_ISWINLOGON2,
+ THREADSTATE_UNKNOWN17,
+ THREADSTATE_UNKNOWN18,
+ THREADSTATE_GETTHREADINFO = 100, /* FIXME: Delete this HACK */
+ THREADSTATE_PROGMANWINDOW, /* FIXME: Delete this HACK */
+ THREADSTATE_TASKMANWINDOW, /* FIXME: Delete this HACK */
};
DWORD_PTR
diff --git a/win32ss/user/ntuser/misc.c b/win32ss/user/ntuser/misc.c
index 10fa0144f16..00393431603 100644
--- a/win32ss/user/ntuser/misc.c
+++ b/win32ss/user/ntuser/misc.c
@@ -232,6 +232,7 @@ NtUserGetThreadState(
DWORD Routine)
{
DWORD_PTR ret = 0;
+ PTHREADINFO pti;
TRACE("Enter NtUserGetThreadState\n");
if (Routine != THREADSTATE_GETTHREADINFO)
@@ -243,9 +244,11 @@ NtUserGetThreadState(
UserEnterExclusive();
}
+ pti = PsGetCurrentThreadWin32Thread();
+
switch (Routine)
{
- case THREADSTATE_GETTHREADINFO:
+ case THREADSTATE_GETTHREADINFO: /* FIXME: Delete this HACK */
GetW32ThreadInfo();
break;
case THREADSTATE_FOCUSWINDOW:
@@ -255,10 +258,10 @@ NtUserGetThreadState(
/* FIXME: Should use UserEnterShared */
ret = (DWORD_PTR)IntGetCapture();
break;
- case THREADSTATE_PROGMANWINDOW:
+ case THREADSTATE_PROGMANWINDOW: /* FIXME: Delete this HACK */
ret = (DWORD_PTR)GetW32ThreadInfo()->pDeskInfo->hProgmanWindow;
break;
- case THREADSTATE_TASKMANWINDOW:
+ case THREADSTATE_TASKMANWINDOW: /* FIXME: Delete this HACK */
ret = (DWORD_PTR)GetW32ThreadInfo()->pDeskInfo->hTaskManWindow;
break;
case THREADSTATE_ACTIVEWINDOW:
@@ -293,12 +296,8 @@ NtUserGetThreadState(
break;
case THREADSTATE_UPTIMELASTREAD:
- {
- PTHREADINFO pti;
- pti = PsGetCurrentThreadWin32Thread();
- pti->pcti->timeLastRead = EngGetTickCount32();
- break;
- }
+ pti->pcti->timeLastRead = EngGetTickCount32();
+ break;
case THREADSTATE_GETINPUTSTATE:
ret =
LOWORD(IntGetQueueStatus(QS_POSTMESSAGE|QS_TIMER|QS_PAINT|QS_SENDMESSAGE|QS_INPUT)) &
(QS_KEY | QS_MOUSEBUTTON);
@@ -313,9 +312,33 @@ NtUserGetThreadState(
break;
case THREADSTATE_GETMESSAGEEXTRAINFO:
ret = (DWORD_PTR)MsqGetMessageExtraInfo();
- break;
- case THREADSTATE_UNKNOWN13:
- ret = FALSE; /* FIXME: See imm32 */
+ break;
+ case THREADSTATE_DEFAULTIMEWINDOW:
+ if (pti->spwndDefaultIme)
+ ret = (ULONG_PTR)UserHMGetHandle(pti->spwndDefaultIme);
+ break;
+ case THREADSTATE_DEFAULTINPUTCONTEXT:
+ if (pti->spDefaultImc)
+ ret = (ULONG_PTR)UserHMGetHandle(pti->spDefaultImc);
+ break;
+ case THREADSTATE_CHANGEBITS:
+ ret = pti->pcti->fsChangeBits;
+ break;
+ case THREADSTATE_IMECOMPATFLAGS:
+ ret = pti->ppi->dwImeCompatFlags;
+ break;
+ case THREADSTATE_OLDKEYBOARDLAYOUT:
+ ret = (ULONG_PTR)pti->hklPrev;
+ break;
+ case THREADSTATE_ISWINLOGON:
+ case THREADSTATE_ISWINLOGON2:
+ ret = (gpidLogon == PsGetCurrentProcessId());
+ break;
+ case THREADSTATE_UNKNOWN17:
+ /* FIXME */
+ break;
+ case THREADSTATE_UNKNOWN18:
+ ret = TRUE;
break;
}