https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cdf3b5e85ac106e9e0fce…
commit cdf3b5e85ac106e9e0fce956054621aebaa9cc1f
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sat Jan 1 20:56:50 2022 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Sat Jan 1 20:56:50 2022 +0900
[NTUSER] Implement NtUserQueryInputContext (#4227)
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito(a)reactos.org>
- Modify NtUserQueryInputContext prototype.
- Implement NtUserQueryInputContext function.
- Add enum QUERY_INPUT_CONTEXT (QIC_*) to undocuser.h.
CORE-11700
---
dll/win32/imm32/compstr.c | 2 +-
dll/win32/imm32/ime.c | 4 ++--
dll/win32/imm32/imm.c | 4 ++--
dll/win32/imm32/precomp.h | 2 +-
dll/win32/imm32/utils.c | 4 ++--
sdk/include/reactos/undocuser.h | 9 +++++++++
win32ss/include/ntuser.h | 4 ++--
win32ss/user/ntuser/ntstubs.c | 45 +++++++++++++++++++++++++++++++++++++----
8 files changed, 60 insertions(+), 14 deletions(-)
diff --git a/dll/win32/imm32/compstr.c b/dll/win32/imm32/compstr.c
index 7fa9a0e4111..b49b4a5db19 100644
--- a/dll/win32/imm32/compstr.c
+++ b/dll/win32/imm32/compstr.c
@@ -527,7 +527,7 @@ Imm32SetCompositionStringAW(HIMC hIMC, DWORD dwIndex, LPVOID pComp,
DWORD dwComp
UINT uCodePage;
LPRECONVERTSTRING pRS;
- dwThreadId = NtUserQueryInputContext(hIMC, 1);
+ dwThreadId = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTTHREADID);
if (dwThreadId != GetCurrentThreadId())
return FALSE;
diff --git a/dll/win32/imm32/ime.c b/dll/win32/imm32/ime.c
index cfe0b66754e..7da1ea09fec 100644
--- a/dll/win32/imm32/ime.c
+++ b/dll/win32/imm32/ime.c
@@ -376,7 +376,7 @@ Imm32GetImeMenuItemsAW(HIMC hIMC, DWORD dwFlags, DWORD dwType, LPVOID
lpImeParen
if (!hIMC)
return 0;
- dwProcessId = NtUserQueryInputContext(hIMC, 0);
+ dwProcessId = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTPROCESSID);
if (dwProcessId == 0)
return 0;
@@ -392,7 +392,7 @@ Imm32GetImeMenuItemsAW(HIMC hIMC, DWORD dwFlags, DWORD dwType, LPVOID
lpImeParen
if (pIC == NULL)
return 0;
- dwThreadId = NtUserQueryInputContext(hIMC, 1);
+ dwThreadId = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTTHREADID);
if (dwThreadId == 0)
{
ImmUnlockIMC(hIMC);
diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c
index c21c5a23567..4ac2cdebb6e 100644
--- a/dll/win32/imm32/imm.c
+++ b/dll/win32/imm32/imm.c
@@ -818,7 +818,7 @@ LPINPUTCONTEXT APIENTRY Imm32LockIMCEx(HIMC hIMC, BOOL fSelect)
if (!pClientImc->hInputContext)
{
- dwThreadId = (DWORD)NtUserQueryInputContext(hIMC, 1);
+ dwThreadId = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTTHREADID);
if (dwThreadId == GetCurrentThreadId() && Imm32IsCiceroMode() &&
!Imm32Is16BitMode())
{
@@ -833,7 +833,7 @@ LPINPUTCONTEXT APIENTRY Imm32LockIMCEx(HIMC hIMC, BOOL fSelect)
}
}
- if (!NtUserQueryInputContext(hIMC, 2))
+ if (!NtUserQueryInputContext(hIMC, QIC_DEFAULTWINDOWIME))
{
RtlLeaveCriticalSection(&pClientImc->cs);
goto Quit;
diff --git a/dll/win32/imm32/precomp.h b/dll/win32/imm32/precomp.h
index 285ab70b8d1..4cd92e5e09d 100644
--- a/dll/win32/imm32/precomp.h
+++ b/dll/win32/imm32/precomp.h
@@ -97,7 +97,7 @@ BOOL APIENTRY Imm32ReleaseIME(HKL hKL);
static inline BOOL Imm32IsCrossThreadAccess(HIMC hIMC)
{
- DWORD dwImeThreadId = NtUserQueryInputContext(hIMC, 1);
+ DWORD dwImeThreadId = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTTHREADID);
DWORD dwThreadId = GetCurrentThreadId();
return (dwImeThreadId != dwThreadId);
}
diff --git a/dll/win32/imm32/utils.c b/dll/win32/imm32/utils.c
index e035fec3ed2..29c2c3adfeb 100644
--- a/dll/win32/imm32/utils.c
+++ b/dll/win32/imm32/utils.c
@@ -186,7 +186,7 @@ BOOL APIENTRY Imm32CheckImcProcess(PIMC pIMC)
return TRUE;
hIMC = pIMC->head.h;
- dwProcessID = NtUserQueryInputContext(hIMC, 0);
+ dwProcessID = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTPROCESSID);
return dwProcessID == (DWORD_PTR)NtCurrentTeb()->ClientId.UniqueProcess;
}
@@ -211,7 +211,7 @@ Imm32NotifyAction(HIMC hIMC, HWND hwnd, DWORD dwAction, DWORD_PTR
dwIndex, DWORD
if (dwAction)
{
- dwThreadId = NtUserQueryInputContext(hIMC, 1);
+ dwThreadId = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTTHREADID);
if (dwThreadId)
{
/* find keyboard layout and lock it */
diff --git a/sdk/include/reactos/undocuser.h b/sdk/include/reactos/undocuser.h
index f63e5cd4153..ca13a8b0239 100644
--- a/sdk/include/reactos/undocuser.h
+++ b/sdk/include/reactos/undocuser.h
@@ -379,6 +379,15 @@ BOOL WINAPI RegisterUserApiHook(PUSERAPIHOOKINFO puah);
BOOL WINAPI UnregisterUserApiHook(VOID);
+/* dwType for NtUserQueryInputContext */
+typedef enum _QUERY_INPUT_CONTEXT
+{
+ QIC_INPUTPROCESSID = 0,
+ QIC_INPUTTHREADID,
+ QIC_DEFAULTWINDOWIME,
+ QIC_DEFAULTIMC
+} QUERY_INPUT_CONTEXT;
+
#ifdef __cplusplus
} /* extern "C" */
#endif /* defined(__cplusplus) */
diff --git a/win32ss/include/ntuser.h b/win32ss/include/ntuser.h
index 9d936530827..0e6d4c3b4d9 100644
--- a/win32ss/include/ntuser.h
+++ b/win32ss/include/ntuser.h
@@ -2877,11 +2877,11 @@ NtUserQueryInformationThread(
OUT PVOID ThreadInformation,
IN ULONG ThreadInformationLength);
-DWORD
+DWORD_PTR
NTAPI
NtUserQueryInputContext(
HIMC hIMC,
- DWORD dwUnknown2);
+ DWORD dwType);
DWORD
NTAPI
diff --git a/win32ss/user/ntuser/ntstubs.c b/win32ss/user/ntuser/ntstubs.c
index 9d7b624151b..1a173714958 100644
--- a/win32ss/user/ntuser/ntstubs.c
+++ b/win32ss/user/ntuser/ntstubs.c
@@ -647,14 +647,51 @@ Quit:
return Status;
}
-DWORD
+DWORD_PTR
APIENTRY
NtUserQueryInputContext(
HIMC hIMC,
- DWORD dwUnknown2)
+ DWORD dwType)
{
- TRACE("NtUserQueryInputContext(%p, 0x%lX)\n", hIMC, dwUnknown2);
- return 0;
+ PIMC pIMC;
+ PTHREADINFO ptiIMC;
+ DWORD_PTR ret = 0;
+
+ UserEnterExclusive();
+
+ if (!IS_IMM_MODE())
+ goto Quit;
+
+ pIMC = UserGetObject(gHandleTable, hIMC, TYPE_INPUTCONTEXT);
+ if (!pIMC)
+ goto Quit;
+
+ ptiIMC = pIMC->head.pti;
+
+ switch (dwType)
+ {
+ case QIC_INPUTPROCESSID:
+ ret = (DWORD_PTR)PsGetThreadProcessId(ptiIMC->pEThread);
+ break;
+
+ case QIC_INPUTTHREADID:
+ ret = (DWORD_PTR)PsGetThreadId(ptiIMC->pEThread);
+ break;
+
+ case QIC_DEFAULTWINDOWIME:
+ if (ptiIMC->spwndDefaultIme)
+ ret = (DWORD_PTR)UserHMGetHandle(ptiIMC->spwndDefaultIme);
+ break;
+
+ case QIC_DEFAULTIMC:
+ if (ptiIMC->spDefaultImc)
+ ret = (DWORD_PTR)UserHMGetHandle(ptiIMC->spDefaultImc);
+ break;
+ }
+
+Quit:
+ UserLeave();
+ return ret;
}
BOOL