[C#/COMMON] Process 클래스 : 지정 프로세스의 IME 모드(한글/영문 모드) 구하기
■ Process 클래스를 사용해 지정 프로세스의 IME 모드(한글/영문 모드)를 구하는 방법을 보여준다. ▶ IMEMode.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
namespace TestProject { /// <summary> /// IME 모드 /// </summary> public enum IMEMode { /// <summary> /// 한글 모드 /// </summary> Korean, /// <summary> /// 영문 모드 /// </summary> English, /// <summary> /// 에러 /// </summary> Error } } |
▶ IMEHelper.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
using System; using System.Diagnostics; using System.Runtime.InteropServices; namespace TestProject { /// <summary> /// IME 헬퍼 /// </summary> public static class IMEHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Import ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 디폴트 IME 윈도우 구하기 - ImmGetDefaultIMEWnd(windowHandle) /// <summary> /// 디폴트 IME 윈도우 구하기 /// </summary> /// <param name="windowHandle">윈도우</param> /// <returns>디폴트 IME 윈도우 핸들</returns> [DllImport("imm32.dll")] private static extern IntPtr ImmGetDefaultIMEWnd(IntPtr windowHandle); #endregion #region 메시지 보내기 - SendMessage(windowHandle, message, wordParameter, longParameter) /// <summary> /// 메시지 보내기 /// </summary> /// <param name="windowHandle">윈도우 핸들</param> /// <param name="message">메시지</param> /// <param name="wordParameter">WORD 매개 변수</param> /// <param name="longParameter">LONG 매개 변수</param> /// <returns>처리 결과</returns> [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr windowHandle, uint message, IntPtr wordParameter, IntPtr longParameter); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// WM_IME_CONTROL /// </summary> private const int WM_IME_CONTROL = 643; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region IME 모드 구하기 - GetIMEMode(process) /// <summary> /// IME 모드 구하기 /// </summary> /// <param name="process">프로세스</param> /// <returns>IME 모드</returns> public static IMEMode GetIMEMode(Process process) { if(process == null) { return IMEMode.Error; } IntPtr windowHandle = process.MainWindowHandle; IntPtr imeDefaultWindowHandle = ImmGetDefaultIMEWnd(windowHandle); IntPtr status = SendMessage(imeDefaultWindowHandle, WM_IME_CONTROL, new IntPtr(0x5), new IntPtr(0)); if(status.ToInt32() != 0) { return IMEMode.Korean; } else { return IMEMode.English; } } #endregion } } |
▶ Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
using System; using System.Diagnostics; using System.Threading; namespace TestProject { /// <summary> /// 프로그램 /// </summary> class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> private static void Main() { Process process = new Process(); process.StartInfo.FileName = "notepad.exe"; process.StartInfo.Arguments = null; process.Start(); process.WaitForInputIdle(100); while(true) { Console.WriteLine(IMEHelper.GetIMEMode(process)); Thread.Sleep(1000); } } #endregion } } |
TestProject.zip