日本語のフリガナを取得するには

日本語のフリガナを取得してみます。
キーワードは「ImmGetCompositionString()関数」です。
ImmGetCompositionString()関数は日本語入力の変換に関する制御を行う関数です。
例えば変換中の全角文字を取得することもできます。

今回はその中でフリガナを取得するフラグを設定しています。

実行中の様子

Dim hIMC As Long
Private Sub Form_Load()
    Me.Label3.Caption = ""
    Me.Text1.Text = ""
    hIMC = ImmGetContext(Me.Text1.hWnd)                 'IME入力コンテキストの取得
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Call ImmReleaseContext(Me.Text1.hWnd, hIMC) 'IME入力コンテキストの開放 End Sub
Private Sub Form_Unload(Cancel As Integer) Call ImmReleaseContext(Me.Text1.hWnd, hIMC) 'IME入力コンテキストの開放 End Sub
Private Sub Text1_Change() Dim nSize As Long, temp As String 'バイト数の取得 nSize = ImmGetCompositionString(hIMC, GCS_RESULTREADSTR, vbNullString, 0) 'バッファの確保 temp = String(nSize, Chr(0)) '読みの取得 Call ImmGetCompositionString(hIMC, GCS_RESULTREADSTR, temp, Len(temp)) Me.Label3.Caption = temp End Sub
ダウンロード