IME.bas
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:3k
- Attribute VB_Name = "IME"
- Private kln As String
- Public hKBAstr(24) As String, hCurKBDLayout As Long
- Public hKBA(24) As Long
- Sub setIME(ListIndex As Long)
- Dim tt As Long
-
- If ListIndex = -1 Then '如果用户尚未选择输入法,显示出错信息
- MsgBox "请先选择一个输入法"
- Exit Sub
- End If
- '改变输入法顺序
- kln = String(8, 0)
- tt = hKBA(ListIndex)
- If (tt = 0) Then
- tt = LoadKeyboardLayout("00000409", KLF_REORDER)
- ActivateKeyboardLayout tt, 0
- Else
- ActivateKeyboardLayout tt, 0 '则处如果TT为0就切换输入
- End If
- res = GetKeyboardLayoutName(kln)
- res = LoadKeyboardLayout(kln, KLF_REORDER)
- End Sub
-
- Sub StartmyIME()
- Dim Buff As String, BuffLen As Long
- Dim RetStr As String, hKB(24) As Long
- Dim RetCount As Long
- Dim NoOfKBDLayout As Long, i As Long, j As Long
- Dim tt
- tt = 0
- Buff = String(255, 0)
- hCurKBDLayout = GetKeyboardLayout(0) '取得目前的输入法
- NoOfKBDLayout = GetKeyboardLayoutList(25, hKB(0)) '取得所有输入法
-
- For i = 1 To NoOfKBDLayout
- If ImmIsIME(hKB(i)) = 1 Then '中文输入法
- BuffLen = 255
- RetCount = ImmGetDescription(hKB(i), Buff, BuffLen)
- RetStr = Left(Buff, RetCount)
- If (Len(RetStr)) Then
- hKBA(tt) = hKB(i)
- hKBAstr(tt) = RetStr
- tt = tt + 1
- End If
- Else
- RetStr = "English (American)" '英文输入法
- hKBAstr(tt) = RetStr
- End If
- Next
-
- ActivateKeyboardLayout hCurKBDLayout, 0 '恢复原来的输入法
- End Sub
- Function MyCutStr(CutString As String, CutChar As String) As String
- '用给定的字符串把字符串切成两半,并半部返回,后半部放入第一个参数中
- Dim mypos As Integer
- If Len(CutString) > 2 Then
- mypos = InStr(1, CutString, CutChar, 1)
- If mypos = 0 Then
- CutString = "1"
- Else
- MyCutStr = Left(CutString, mypos - 1)
- CutString = Right(CutString, Len(CutString) - mypos)
- End If
- Else
- CutString = "1"
- End If
- If CutString = "" Then
- CutString = "1"
- End If
- End Function
- Function CodeToChinese(KeyAscii As Integer)
- Dim bb(10) As Byte
- Dim ret As String
- If (KeyAscii >= 0) Then
- ret = Chr(KeyAscii)
- Else
- f = Hex(KeyAscii)
- If Len(f) = 4 Then
- bb(0) = CInt("&H" + Mid(f, 1, 2))
- bb(1) = CInt("&H" + Mid(f, 3, 2))
-
- ret = StrConv(bb, vbUnicode)
- ret = Mid(ret, 1, 1)
- End If
- ret = ret
- End If
-
- CodeToChinese = ret
-
- End Function