用这几个api函数,应该可以满足你的要求:
GetKeyboardLayoutList
ImmGetDescription
ImmIsIME
ActivateKeyboardLayout
GetKeyboardLayout再给你一个例子
Option Explicit
Const KL_NAMELENGTH = 9
Private Declare Function GetKeyboardLayoutList Lib "user32" _
(ByVal nBuff As Long, lpList As Long) As LongPrivate Declare Function ImmGetDescription Lib "imm32.dll" _
Alias "ImmGetDescriptionA" (ByVal HKL As Long, _
ByVal lpsz As String, ByVal uBufLen As Long) As LongPrivate Declare Function ImmIsIME Lib "imm32.dll" (ByVal HKL As Long) As LongPrivate Declare Function ActivateKeyboardLayout Lib "user32" _
(ByVal HKL As Long, ByVal flags As Long) As LongPrivate Declare Function GetKeyboardLayout Lib "user32" _
(ByVal dwLayout As Long) As Long
Private Declare Function GetKeyboardLayoutName Lib "user32" Alias "GetKeyboardLayoutNameA" (ByVal pwszKLID As String) As Long
Private Sub Command1_Click()
If Trim(Combo1.Text) <> "" Then
ActivateKeyboardLayout GetKBLayout_Handle_ByName(Combo1.Text), 0 '激活某种输入法
End If
End SubPrivate Sub Form_Load()
Dim StrName As String
Dim hCurKBDLayout As Long
Dim NoOfKBDLayout As Long, i As Long, j As LongDim hKB(24) As Long, BuffLen As LongDim Buff As StringDim RetStr As StringDim RetCount As Long
StrName = String(KL_NAMELENGTH, 0)Buff = String(255, 0)
GetKeyboardLayoutName StrName
hCurKBDLayout = GetKeyboardLayout(0) '取得目前keyboard layoutNoOfKBDLayout = GetKeyboardLayoutList(25, hKB(0)) '取得所有输入法的hkeysFor i = 1 To NoOfKBDLayout If ImmIsIME(hKB(i - 1)) = 1 Then '中文输入法 BuffLen = 255 RetCount = ImmGetDescription(hKB(i - 1), Buff, BuffLen) RetStr = Left(Buff, RetCount)
RetStr = Trim(Buff)
Combo1.AddItem RetStr Else RetStr = "English (American)" '假设我们的win95非Ime 者只有English Combo1.AddItem RetStr '若有其他者,要去取得keyboardLayout End If ' Name再去Registry中找其对应的名称 If hKB(i - 1) = hCurKBDLayout Then Combo1.Text = RetStr End IfNext'ActivateKeyboardLayout hCurKBDLayout, 0 '恢复原来输入法
'ActivateKeyboardLayout hKB(1), 0 '这种方法可以激活某种输入法
'ActivateKeyboardLayout hKB(2), 0
End SubPrivate Function GetKBLayout_Handle_ByName(Name As String) As Long
Dim hKB(20) As Long, i As Integer
Dim BufferLen As Long
Dim RetStr As String
Dim NumOfKBLayout As Integer
Dim Buffer As String
Dim RetCount As Integer
Buffer = String(255, 0)
BufferLen = 255
NumOfKBLayout = GetKeyboardLayoutList(21, hKB(0))
For i = 0 To NumOfKBLayout - 1
RetCount = ImmGetDescription(hKB(i), Buffer, BufferLen)
If RetCount <> 0 Then
RetStr = Left(Buffer, RetCount)
If Left(RetStr, 5) = Left(Trim(Combo1.Text), 5) Then
GetKBLayout_Handle_ByName = hKB(i)
Exit For
End If
End If
Next
End Function
GetKeyboardLayoutList
ImmGetDescription
ImmIsIME
ActivateKeyboardLayout
GetKeyboardLayout再给你一个例子
Option Explicit
Const KL_NAMELENGTH = 9
Private Declare Function GetKeyboardLayoutList Lib "user32" _
(ByVal nBuff As Long, lpList As Long) As LongPrivate Declare Function ImmGetDescription Lib "imm32.dll" _
Alias "ImmGetDescriptionA" (ByVal HKL As Long, _
ByVal lpsz As String, ByVal uBufLen As Long) As LongPrivate Declare Function ImmIsIME Lib "imm32.dll" (ByVal HKL As Long) As LongPrivate Declare Function ActivateKeyboardLayout Lib "user32" _
(ByVal HKL As Long, ByVal flags As Long) As LongPrivate Declare Function GetKeyboardLayout Lib "user32" _
(ByVal dwLayout As Long) As Long
Private Declare Function GetKeyboardLayoutName Lib "user32" Alias "GetKeyboardLayoutNameA" (ByVal pwszKLID As String) As Long
Private Sub Command1_Click()
If Trim(Combo1.Text) <> "" Then
ActivateKeyboardLayout GetKBLayout_Handle_ByName(Combo1.Text), 0 '激活某种输入法
End If
End SubPrivate Sub Form_Load()
Dim StrName As String
Dim hCurKBDLayout As Long
Dim NoOfKBDLayout As Long, i As Long, j As LongDim hKB(24) As Long, BuffLen As LongDim Buff As StringDim RetStr As StringDim RetCount As Long
StrName = String(KL_NAMELENGTH, 0)Buff = String(255, 0)
GetKeyboardLayoutName StrName
hCurKBDLayout = GetKeyboardLayout(0) '取得目前keyboard layoutNoOfKBDLayout = GetKeyboardLayoutList(25, hKB(0)) '取得所有输入法的hkeysFor i = 1 To NoOfKBDLayout If ImmIsIME(hKB(i - 1)) = 1 Then '中文输入法 BuffLen = 255 RetCount = ImmGetDescription(hKB(i - 1), Buff, BuffLen) RetStr = Left(Buff, RetCount)
RetStr = Trim(Buff)
Combo1.AddItem RetStr Else RetStr = "English (American)" '假设我们的win95非Ime 者只有English Combo1.AddItem RetStr '若有其他者,要去取得keyboardLayout End If ' Name再去Registry中找其对应的名称 If hKB(i - 1) = hCurKBDLayout Then Combo1.Text = RetStr End IfNext'ActivateKeyboardLayout hCurKBDLayout, 0 '恢复原来输入法
'ActivateKeyboardLayout hKB(1), 0 '这种方法可以激活某种输入法
'ActivateKeyboardLayout hKB(2), 0
End SubPrivate Function GetKBLayout_Handle_ByName(Name As String) As Long
Dim hKB(20) As Long, i As Integer
Dim BufferLen As Long
Dim RetStr As String
Dim NumOfKBLayout As Integer
Dim Buffer As String
Dim RetCount As Integer
Buffer = String(255, 0)
BufferLen = 255
NumOfKBLayout = GetKeyboardLayoutList(21, hKB(0))
For i = 0 To NumOfKBLayout - 1
RetCount = ImmGetDescription(hKB(i), Buffer, BufferLen)
If RetCount <> 0 Then
RetStr = Left(Buffer, RetCount)
If Left(RetStr, 5) = Left(Trim(Combo1.Text), 5) Then
GetKBLayout_Handle_ByName = hKB(i)
Exit For
End If
End If
Next
End Function
解决方案 »
- 使用MAPI做的邮件发送程序老是被OE提示需要压缩邮件清理空间怎么办?(50分)
- 请教高手:请问vb中能调用matlab吗?
- 五一前终于升星,散分祝各位GGJJDDMM假期愉快!^_^
- setfactory打包时如何使用序列号?(无内容)
- 溢出错误,麻烦来看看!
- 菜鸟问题:ado与sql sever如何建立连接?有什么比较好的书可以看么?
- 怎样用VB中PICTURE的图形保存一个图片文件(文件大小要很小的,越小越好)
- ?怎么样才能mshflexgrid第0列除去呢?因为我觉得它没有什么用?
- 有沒有深圳的朋友﹐知道報考MCSD在哪儿報名﹖
- 我想写一个通讯录,但我不想用数据库。
- datagrid的数据源如何设置成动态的啊——详细内容请进
- 关于导入的问题..
ActivateKeyboardLayout hKB(1), 0 '这种方法可以激活某种输入法
他们两个都可以激活某个输入法,但是好像 ActivateKeyboardLayout如果指定 KLF_REORDER 的话,只会改变GetKeylayoutlist中的顺序,而不会改变显示在任务栏上的输入法的顺序,这两个顺序怎么不一样?而用LoadKeyboardlayout就可以一致!还有使用ActivateKeyboardLayout之前要先 LoadKeyboardlayout进来,但是一般情况好像都在了,应该不用Load了!
可是 hCurKBDLayout = GetKeyboardLayout(0) 返回值总是负数,
hCurKBDLayout = GetKeyboardLayout(1) 返回不定的输入法
大哥救救我
hCurKBDLayout = GetKeyboardLayout(0) 获得目前键盘的布局
当你想激活原来输入发的时候就可以
ActivateKeyboardLayout hCurKBDLayout ,0
激活原来的输入法了,这是我想法,主要我不知道你那出什么问题,所只能简单的说说