Excel VBA高级编程:如何用combox或listview列出系统中所有的输入法?

2015-04-13 17:32 阅读 317 次 评论关闭

如何用comboxlistview列出系统中所有的输入法

Private Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, lpList As Long) As Long
Private Declare Function ImmIsIME Lib "imm32.dll" (ByVal HKL 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
Private Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long
Private hKB(24) As Long, BuffLen As Long, RetCount As Long
Private Buff As String, RetStr As String

Private Sub UserForm_Initialize()
Buff = String(255, 0)    '預設255個字元
NowLayout = GetKeyboardLayout(0) '取得目前的輸入法
AllLayout = GetKeyboardLayoutList(25, hKB(0)) '取得系統內使用的輸入法(集合)
For i = 1 To AllLayout
RetID = hKB(i - 1)
If ImmIsIME(RetID) = 1 Then  '中文輸入法(大易.注音.新注音.倉詰..)
BuffLen = 255    ''預設255個字元
RetCount = ImmGetDescription(hKB(i - 1), Buff, BuffLen)
RetStr = Application.WorksheetFunction.Trim(Left(Buff, RetCount))
ListBox1.AddItem RetStr
ListBox2.AddItem RetID
Else
RetStr = "English (英數)" '英數輸入法
ListBox1.AddItem RetStr
ListBox2.AddItem RetID
End If
Next
ActivateKeyboardLayout NowLayout, 0 '恢復原有的輸入法

End Sub

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:Excel VBA高级编程:如何用combox或listview列出系统中所有的输入法? | 猎微网

评论已关闭!