请问当text1_gotfocus()时如何打开指定输入法?
当text1_lostfocus()时如何保存当前输入法,以便下一次text1_gotfocus()时打开用户改变后的输入法?

解决方案 »

  1.   

    1、在模块中定义以下api或变量
    Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long
    Declare Function ActivateKeyboardLayout Lib "user32" (ByVal hkl As Long, ByVal _
            flags As Long) As Long
    Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, _
            lpList As Long) As Long
    Declare Function ImmGetDescription Lib "imm32.dll" Alias "ImmGetDescriptionA" (ByVal _
            hkl As Long, ByVal lpsz As String, ByVal uBufLen As Long) As LongPublic lngImeNow As Long
    Public lngImeEng As Long2、在模块中定义以下过程:
    Sub GetEngImeValue()
        Dim arrIme(1 To 16) As Long
        Dim strAll As String * 256
        Dim strTmp As String
        Dim lngResult As Long
        Dim lngLoop As Long
        lngResult = GetKeyboardLayoutList(32, arrIme(1))
        If lngResult Then
            For lngLoop = 1 To lngResult
                ImmGetDescription arrIme(lngLoop), strAll, 256
                If InStr(strAll, Chr(0)) = 1 Then
                    strTmp = ""
                Else
                    strTmp = Left$(strAll, InStr(strAll, Chr(0)))
                End If
                If Trim(strTmp) = "" Then lngImeEng = arrIme(lngLoop)
            Next lngLoop
        End If
    End Sub3、在form的load中加入以下代码:(当然你也可以在此设置你要的输入法)
        Call GetEngImeValue
    lngImeNow = lngImeEng
    4、在text1_lostfocus()事件中加入以下代码:
       lngImeNow = GetKeyboardLayout(0)5、在text1_gotfocus()事件中加入以下代码:
       ActivateKeyboardLayout lngImeEng, 1
       ActivateKeyboardLayout lngImeNow, 1
      

  2.   

    以前讨论过,以 输入法为关键字 在vb api论坛内搜索
      

  3.   

    Option ExplicitPrivate Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, _
            lpList As Long) As Long
    Private Declare Function GetKeyboardLayoutName Lib "user32" Alias "GetKeyboardLayoutNameA" _
            (ByVal pwszKLID As String) As Long
    Private Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long
    Private Declare Function ImmGetDescription Lib "imm32.dll" Alias "ImmGetDescriptionA" (ByVal _
            hkl As Long, ByVal lpsz As String, ByVal uBufLen As Long) As Long
    Private Declare Function ActivateKeyboardLayout Lib "user32" (ByVal hkl As Long, ByVal _
            flags As Long) As Long
            
    Const IME_CONFIG_GENERAL = 1
    Const KLF_REORDER = &H8
    Const KLF_ACTIVATE = &H1Dim la(1 To 16) As Long
    Dim ActIme As LongPrivate Sub Combo1_Click()
        ActIme = la(Combo1.ListIndex + 1)
        Debug.Print ActIme
        Text1.SetFocus
    End SubPrivate Sub Form_Load()
        Dim astr As String * 256
        Dim bstr As String
        Dim x, hMem, i As Long
        
        x = GetKeyboardLayoutList(32, la(1))
        Combo1.Clear
        If x Then
            For i = 1 To x
                ImmGetDescription la(i), astr, 256
                If InStr(astr, Chr(0)) = 1 Then
                    bstr = ""
                Else
                    bstr = Left$(astr, InStr(astr, Chr(0)))
                End If
            
                If Trim(bstr) = "" Then
                    Combo1.AddItem "英语(美国)"
                Else
                    Combo1.AddItem bstr
                End If
            Next i
        End If
    End SubPrivate Sub Text1_GotFocus()
        If Combo1.ListCount > 0 Then
            ActivateKeyboardLayout ActIme, 1
        End If
    End Sub