728x90
반응형
▶ IMEMode.cs
namespace TestProject
{
/// <summary>
/// IME 모드
/// </summary>
public enum IMEMode
{
/// <summary>
/// 한글 모드
/// </summary>
Korean,
/// <summary>
/// 영문 모드
/// </summary>
English,
/// <summary>
/// 에러
/// </summary>
Error
}
}
▶ IMEHelper.cs
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
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
}
}
728x90
반응형
'C# > Common' 카테고리의 다른 글
[C#/COMMON] 하위 워드 구하기 (0) | 2021.01.24 |
---|---|
[C#/COMMON] 닷넷 어셈블리 2.0 버전을 닷넷 4.5 프로젝트에서 사용하기 (0) | 2021.01.22 |
[C#/COMMON] AppDomain 클래스 : AssemblyResolve 이벤트를 사용해 포터블 실행 파일(Portable Executable File) 만들기 (0) | 2021.01.22 |
[C#/COMMON] 모니터 화면 끄기/켜기 (0) | 2021.01.22 |
[C#/COMMON] GuidAttribute 클래스 : 프로젝트의 COM 노출 GUID 구하기 (0) | 2021.01.22 |
[C#/COMMON] Process 클래스 : 지정 프로세스의 IME 모드(한글/영문 모드) 구하기 (0) | 2021.01.22 |
[C#/COMMON] NetworkChange 클래스 : NetworkAddressChanged 정적 이벤트를 사용해 네트워크 주소 변경시 처리하기 (0) | 2021.01.22 |
[C#/COMMON] NetworkChange 클래스 : NetworkAvailabilityChanged 정적 이벤트를 사용해 네트워크 가용 여부 변경시 처리하기 (0) | 2021.01.22 |
[C#/COMMON] MIME 타입 딕셔너리 구하기 (0) | 2021.01.21 |
[C#/COMMON] 다른 프로세스(윈도우)에 문자열 보내기 (0) | 2021.01.21 |
[C#/COMMON] Process 클래스 : 메모장 EDIT 윈도우 핸들 구하기 (0) | 2021.01.21 |
댓글을 달아 주세요