2009年10月16日 星期五

VS 2005 Winform 輸入法全型切換錯誤問題

首先在專案中新增一個Class
Public Class ImeForm

Inherits System.Windows.Forms.Form

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
Private Declare Function ImmSimulateHotKey Lib "imm32.dll" (ByVal hwnd As Integer, ByVal dw As Integer) As Integer

Private Sub Form_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
For Each objCtl As Control In Me.Controls
AddHandler objCtl.GotFocus, AddressOf ControlIME
Next
End Sub

Private Sub Form_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
ControlIME(Me, Nothing)
End Sub

Private Shared Sub ControlIME(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lngStatus As Long, lngSt As Long, h As IntPtr = sender.Handle
ImmGetConversionStatus(ImmGetContext(h), lngStatus, lngSt)
If lngStatus = 9 Then ImmSimulateHotKey(h, 113)
End Sub

End Class

繼承ImeForm
Public Class ControlCenter
Inherits ImeForm


沒有留言:

張貼留言