GUI开发,屏蔽输入法影响
public class WindowsImManager {
private static boolean status = true;
private static native WinNT.HANDLE ImmGetContext(WinDef.HWND hwnd);
private static native WinNT.HANDLE ImmAssociateContext(WinDef.HWND hwnd, WinNT.HANDLE himc);
private static native boolean ImmReleaseContext(WinDef.HWND hwnd, WinNT.HANDLE himc);
private static native WinNT.HANDLE ImmCreateContext();
private static native boolean ImmDestroyContext(WinNT.HANDLE himc);
static {
Native.register("imm32");
}
private static final User32 u = User32.INSTANCE;
public static void makeOn() {
if (status) {
return;
}
status = true;
WinDef.HWND hwnd = u.GetForegroundWindow();
WinNT.HANDLE himc = ImmGetContext(hwnd);
if (himc == null) {
himc = ImmCreateContext();
ImmAssociateContext(hwnd, himc);
}
ImmReleaseContext(hwnd, himc);
}
public static void makeOff() {
if (!status) {
return;
}
status = false;
WinDef.HWND hwnd = u.GetForegroundWindow();
WinNT.HANDLE himc = ImmAssociateContext(hwnd, null);
if (himc != null) {
ImmDestroyContext(himc);
}
ImmReleaseContext(hwnd, himc);
}
}