Excel :如何用combox或listview列出系统中所有的输入法
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)) '取得系統內使用的輸入法(集合)
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