본문 바로가기

자료

[C#/ VB.NET] [API] 한/영 키 상태 값 구하기

728x90

[C#/ VB.NET] [API] 한/영 키 상태 값 구하기


 

 

Imports System.Runtime.InteropServices

Public Class Form1

    Private Declare Function ImmGetContext Lib "imm32.dll" (ByVal hwnd As Integer) As Integer
    Private Declare Function ImmGetConversionStatus Lib "imm32.dll" (ByVal himc As Integer, ByRef lpdw As Integer, ByRef lpdw2 As Integer) As Integer
Declare Function ImmReleaseContext Lib "imm32.dll" (ByVal hWnd As Integer, ByVal hIMC As Integer) As Integer

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        MyBase.OnLoad(e)

        Timer1.Start()

    End Sub

    Protected Overrides Sub OnClosed(ByVal e As System.EventArgs)
        MyBase.OnClosed(e)

        Timer1.Stop()

    End Sub


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Try
            Dim hIMC As Integer
            Dim dwConversion As Integer, dwSentence As Integer
            Dim rc As Integer

            hIMC = ImmGetContext(textBox1.Handle.ToInt32)
            'TextBox 한영키 상태값 얻기...
            rc = ImmGetConversionStatus(hIMC, dwConversion, dwSentence)

            If dwConversion = 0 Then
                label1.Text = "한영키 상태 : 영문"
            Else
                label1.Text = "한영키 상태 : 한글"
            End If
        Catch ex As Exception
            Debug.WriteLine(ex.Message.ToString())
        End Try

    End Sub

End Class

 

 

 

 

728x90