I have a Qt Editbox in a WinForms application. I forward the mouse and key events from WinForms to the Qt Editbox.
In case of the Input Method Editor, I use this method to position the dialog to the caret in the Qt Editbox:
[DllImport("Imm32.dll")]
public static extern bool ImmSetCompositionWindow(IntPtr hImc, COMPOSITIONFORM pCompForm);
This work fine, the IME appears next to the caret and I can enter characters with the IME in the Qt Editbox.
The problem is that in certain cases the IME doesn't hide automatically, e.g. when I click outside the Qt Editbox. I tried to call this method with the parameter "open" set to false but after that the IME does not appear anymore.
[DllImport("Imm32.dll")]
public static extern bool ImmSetOpenStatus(IntPtr hIMC, bool open);
What is the correct way to hide the IME dialog?
CodePudding user response:
I found the solution: call ImmNotifyIME with NICOMPOSITIONSTR and CPSCANCEL.
[DllImport("imm32.dll")]
public static extern bool ImmNotifyIME(IntPtr hIMC, int dwAction, int dwIndex, int dwValue);
private const int NICOMPOSITIONSTR = 0x0015;
private const int CPSCANCEL = 0x0004;
ImmNotifyIME(immContext, NICOMPOSITIONSTR, CPSCANCEL, 0);