Use VB to add a function of switching Chinese input method in the program

xiaoxiao2021-03-06  43

Idea: First use the getKeyboardLayoutList function to get all the input method, then use immisime to determine if it is a Chinese input method, if yes, get the name of the input method with ImmgetDescription, and finally select the input method you need to activate it. Source code: public Declare Function ActivateKeyboardLayout Lib "user32" (ByVal hkl As Long, ByVal flags As Long) As Long public Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, lpList As Long) As Long public Declare Function GetKeyboardLayout Lib "user32" ( ByVal dwLayout As Long) As Long Public Declare Function ImmGetDescription Lib "imm32.dll" Alias ​​"ImmGetDescriptionA" (ByVal hkl As Long, _ByVal lpsz As String, ByVal uBufLen As Long) As Long Public Declare Function ImmIsIME Lib "imm32.dll" ( BYVAL HKL AS Long) As long public hcurkbdlayout as long public sub purposesrfz () DIM BUFF AS STRING BUFF = String (255, 0) DIM NOOFKBDLAYOUT AS Long Dim Bufflen As Long Dim retstr As String hCurKBDLayout = GetKeyboardLayout (0) 'get the current input method NoOfKBDLayout = GetKeyboardLayoutList (25, hkb (0)) For I = 1 To NoOfKBDLayout If ImmIsIME (hkb (I - 1)) = 1 Then BuffLen = 255 RetCount = ImmgetDescription (HKB (i - 1), buff, bufflen RetStr = Left (buff, retcount) IF = "Intelligent ABC") = "Intelligent ABC"

转载请注明原文地址:https://www.9cbs.com/read-67922.html

New Post(0)