- 題名: カナの取得
- 日時: 2007/06/08 19:43:40
- ID: 19814
- この記事の返信元:
- (なし)
- この記事への返信:
- [19815] Re[1]: カナの取得2007/06/08 19:59:40
- [19859] Re[1]: カナの取得2007/06/17 9:13:32
- [20006] Re[1]: カナの取得2007/07/05 15:44:22 [解決]
- ツリーを表示
どのWindows,どのIMEでも動作するかというと,まったく怪しいものが ありますが,WindowsXpSP2,ATOK2007,VB2005Expでは以下のコードで動作しました。 自己流のコードですが,参考にしてください。 上のテキストボックスに入力すると,下のテキストボックスにカナが 表示されます。 Imports System.Runtime.InteropServices Public Class Form1 Dim WithEvents TextBox1 As New TextBox Dim WithEvents TextBox2 As New TextBox Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Controls.AddRange(New TextBox() {TextBox1, TextBox2}) Me.TextBox2.Top = 30 Dim IMEEvent1 As New IMEEvent(TextBox1) AddHandler IMEEvent1.IMECompositionString, AddressOf IMEEvent_CompositionString End Sub Private Sub IMEEvent_CompositionString(ByVal sender As Object, ByVal e As clsIMEEventArgs) TextBox2.Text += StrConv(e.IMEString, VbStrConv.Wide Or VbStrConv.Katakana) End Sub End Class Public Class IMEEvent Inherits System.Windows.Forms.NativeWindow Public Sub New(ByVal Control As System.Windows.Forms.Control) AssignHandle(Control.Handle) End Sub Public Event IMECompositionString(ByVal sender As Object, ByVal e As clsIMEEventArgs) Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Select Case m.Msg Case WM_IME_COMPOSITION If CType(m.LParam, Integer) And GCS_RESULTREADSTR Then CompositionString(m) End Select MyBase.WndProc(m) End Sub Private Sub CompositionString(ByRef m As System.Windows.Forms.Message) Using IMC As New IMC(Me.Handle) Dim Buf(0) As Byte Dim Length As Integer = ImmGetCompositionString(IMC.Handle, GCS_RESULTREADSTR, Buf(0), 0) ReDim Buf(Length - 1) ImmGetCompositionString(IMC.Handle, GCS_RESULTREADSTR, Buf(0), Length) Dim Args As New clsIMEEventArgs(m, System.Text.Encoding.GetEncoding("shift-jis").GetString(Buf), Nothing) RaiseEvent IMECompositionString(Me, Args) End Using End Sub End Class Public Class clsIMEEventArgs Inherits System.EventArgs Public IMEMessage As System.Windows.Forms.Message Public IMELParam As Integer Public IMEWParam As Integer Public IMEString As String Public IMEList() As String Sub New() MyBase.New() End Sub Sub New(ByRef WindowMessage As System.Windows.Forms.Message, _ ByVal ResultString As String, _ ByVal ResultList() As String) MyBase.New() IMEMessage = WindowMessage IMEString = ResultString IMEList = ResultList End Sub End Class Public Module IMEUtils Structure REGISTERWORD Dim lpReading As String Dim lpWord As String End Structure Public Const GCS_RESULTREADSTR = &H200 Public Const WM_IME_COMPOSITION = &H10F <DllImport("imm32.dll")> _ Public Function ImmGetContext( _ ByVal hWnd As IntPtr) _ As IntPtr End Function <DllImport("imm32.dll")> _ Public Function ImmReleaseContext( _ ByVal hWnd As IntPtr, _ ByVal hIMC As IntPtr) _ As Boolean End Function <DllImport("imm32.dll")> _ Public Function ImmGetCompositionString( _ ByVal hIMC As IntPtr, _ ByVal dwIndwx As Integer, _ ByRef lpBuf As Byte, _ ByVal dwBufLen As Integer) _ As Integer End Function End Module Public Class IMC Implements IDisposable Private _hIMC As IntPtr Private _hWnd As IntPtr Sub New(ByVal hWnd As IntPtr) _hIMC = ImmGetContext(hWnd) _hWnd = hWnd End Sub Public Overloads Sub Dispose() Implements IDisposable.Dispose ImmReleaseContext(_hWnd, _hIMC) GC.SuppressFinalize(Me) End Sub Protected Overrides Sub Finalize() Dispose() End Sub Public ReadOnly Property Handle() As IntPtr Get Return _hIMC End Get End Property End Class
分類:[.NET]
いつもお世話になります。皆様のお力添えをお願いします。
----環境----
OS:Windows XP sp2
言語:VB.NET 2003
画面上に[人名]と[カナ]を入力するTextboxを配置して
人名を入力すると、入力された内容に従いカナを自動的に
セットするようにしたいです。
例)
人名:山田太郎123ABC
カナ:ヤマダタロウ123ABC
どのようにすれば実現出来るのでしょうか?ご教授いただけませんでしょうか。