Dreamine.UI.WinForms 1.0.1
Dreamine.UI.WinForms 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
ImeHelper.cs
이 파일의 문서화 페이지로 가기
1using System.Runtime.InteropServices;
2
4
13internal static class ImeHelper
14{
23 private const uint IME_CMODE_NATIVE = 0x0001;
24
49 [DllImport("imm32.dll")]
50 private static extern IntPtr ImmGetContext(IntPtr hWnd);
51
84 [DllImport("imm32.dll")]
85 private static extern bool ImmReleaseContext(IntPtr hWnd, IntPtr hIMC);
86
111 [DllImport("imm32.dll")]
112 private static extern bool ImmGetOpenStatus(IntPtr hIMC);
113
146 [DllImport("imm32.dll")]
147 private static extern bool ImmSetOpenStatus(IntPtr hIMC, bool open);
148
189 [DllImport("imm32.dll")]
190 private static extern bool ImmGetConversionStatus(IntPtr hIMC, out uint conversion, out uint sentence);
191
232 [DllImport("imm32.dll")]
233 private static extern bool ImmSetConversionStatus(IntPtr hIMC, uint conversion, uint sentence);
234
259 public static bool IsNativeMode(IntPtr hwnd)
260 {
261 if (hwnd == IntPtr.Zero)
262 return false;
263
264 var context = ImmGetContext(hwnd);
265 if (context == IntPtr.Zero)
266 return false;
267
268 try
269 {
270 if (!ImmGetOpenStatus(context))
271 return false;
272
273 return ImmGetConversionStatus(context, out var conversion, out _) &&
274 (conversion & IME_CMODE_NATIVE) != 0;
275 }
276 finally
277 {
278 ImmReleaseContext(hwnd, context);
279 }
280 }
281
314 public static bool SetNativeMode(IntPtr hwnd, bool native)
315 {
316 if (hwnd == IntPtr.Zero)
317 return false;
318
319 var context = ImmGetContext(hwnd);
320 if (context == IntPtr.Zero)
321 return false;
322
323 try
324 {
325 ImmSetOpenStatus(context, native);
326
327 if (ImmGetConversionStatus(context, out var conversion, out var sentence))
328 {
329 conversion = native ? conversion | IME_CMODE_NATIVE : conversion & ~IME_CMODE_NATIVE;
330 ImmSetConversionStatus(context, conversion, sentence);
331 }
332
333 return true;
334 }
335 finally
336 {
337 ImmReleaseContext(hwnd, context);
338 }
339 }
340}