From abd08c5e1264b1e8b6beb3347fae159be0a2f53c Mon Sep 17 00:00:00 2001 From: ryancheung Date: Mon, 24 Aug 2020 15:37:14 +0800 Subject: [PATCH] Fix restoring ImmOpenStatus completely --- ImeSharp/Imm32Manager.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ImeSharp/Imm32Manager.cs b/ImeSharp/Imm32Manager.cs index 6a0a3de..8b30758 100644 --- a/ImeSharp/Imm32Manager.cs +++ b/ImeSharp/Imm32Manager.cs @@ -73,6 +73,8 @@ private IntPtr DefaultImc private static ImmCompositionStringHandler _compositionStringHandler; private static ImmCompositionIntHandler _compositionCursorHandler; + private bool _lastImmOpenStatus; + public Imm32Manager(IntPtr windowHandle) { _windowHandle = windowHandle; @@ -197,7 +199,7 @@ internal bool ProcessMessage(IntPtr hWnd, uint msg, ref IntPtr wParam, ref IntPt // Must re-associate ime context or things won't work. NativeMethods.ImmAssociateContext(_windowHandle, DefaultImc); - if (!NativeMethods.ImmGetOpenStatus(DefaultImc)) + if (_lastImmOpenStatus) NativeMethods.ImmSetOpenStatus(DefaultImc, true); var lParam64 = lParam.ToInt64(); @@ -207,8 +209,9 @@ internal bool ProcessMessage(IntPtr hWnd, uint msg, ref IntPtr wParam, ref IntPt lParam64 &= ~NativeMethods.ISC_SHOWUICOMPOSITIONWINDOW; lParam = (IntPtr)(int)lParam64; } - else - NativeMethods.ImmSetOpenStatus(DefaultImc, false); + break; + case NativeMethods.WM_KILLFOCUS: + _lastImmOpenStatus = NativeMethods.ImmGetOpenStatus(DefaultImc); break; case NativeMethods.WM_IME_NOTIFY: IMENotify(wParam.ToInt32());