첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.01MB

▶ MainForm.cs

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Import
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region IMM 컨텍스트 구하기 - ImmGetContext(windowHandle)

        /// <summary>
        /// IMM 컨텍스트 구하기
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        /// <returns>IMC 컨텍스트 핸들</returns>
        [DllImport("imm32")]
        private static extern IntPtr ImmGetContext(IntPtr windowHandle);

        #endregion
        #region IMM 변환 상태 구하기 - ImmGetConversionStatus(imcHandle, conversion, sentence)

        /// <summary>
        /// IMM 변환 상태 구하기
        /// </summary>
        /// <param name="imcHandle">IMC 핸들</param>
        /// <param name="conversion">변환</param>
        /// <param name="sentence">문장</param>
        /// <returns>처리 결과</returns>
        [DllImport("imm32")]
        private static extern bool ImmGetConversionStatus(IntPtr imcHandle, ref int conversion, ref int sentence);

        #endregion
        #region IMM 컨텍스트 해제하기 - ImmReleaseContext(windowHandle, imcHandle)

        /// <summary>
        /// IMM 컨텍스트 해제하기
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        /// <param name="imcHandle">IMC 핸들</param>
        /// <returns>처리 결과</returns>
        [DllImport("imm32")]
        private static extern bool ImmReleaseContext(IntPtr windowHandle, IntPtr imcHandle);

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 타이머
        /// </summary>
        private Timer timer;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            this.timer = new Timer();

            this.timer.Interval = 300;

            Load            += Form_Load;
            this.timer.Tick += timer_Tick;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

        /// <summary>
        /// 폼 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Load(object sender, EventArgs e)
        {
            this.timer.Start();
        }

        #endregion
        #region 타이머 틱 처리하기 - timer_Tick(sender, e)

        /// <summary>
        /// 타이머 틱 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void timer_Tick(object sender, EventArgs e)
        {
            try
            {
                IntPtr imcHandle = ImmGetContext(this.textBox.Handle);

                int conversion = 0;
                int sentence   = 0;

                ImmGetConversionStatus(imcHandle, ref conversion, ref sentence);
                
                if(conversion == 0)
                {
                    this.statusLabel.Text = "한/영 키 상태 : 영문";
                }
                else
                {
                    this.statusLabel.Text = "한/영 키 상태 : 한글";
                }

                ImmReleaseContext(this.textBox.Handle, imcHandle);
            }
            catch
            {
            }
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요