📄 sample2.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "在VB中切换中文输入法"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.ComboBox Combo1
Height = 315
Left = 240
TabIndex = 2
Top = 240
Width = 3015
End
Begin VB.TextBox Text2
Height = 375
IMEMode = 2 'OFF
Left = 240
TabIndex = 1
Text = "Text2"
Top = 2520
Width = 2895
End
Begin VB.TextBox Text1
Height = 375
Left = 240
TabIndex = 0
Text = "Text1"
Top = 1800
Width = 2895
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, _
lpList As Long) As Long
Private Declare Function GetKeyboardLayoutName Lib "user32" Alias "GetKeyboardLayoutNameA" _
(ByVal pwszKLID As String) As Long
Private Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout 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
Const IME_CONFIG_GENERAL = 1
Const KLF_REORDER = &H8
Const KLF_ACTIVATE = &H1
Dim la(1 To 16) As Long
Dim ActIme As Long
Private Sub Combo1_Click()
ActIme = la(Combo1.ListIndex + 1)
Debug.Print ActIme
Text1.SetFocus
End Sub
Private Sub Form_Load()
Dim astr As String * 256
Dim bstr As String
Dim x, hMem, i As Long
x = GetKeyboardLayoutList(32, la(1))
Combo1.Clear
If x Then
For i = 1 To x
ImmGetDescription la(i), astr, 256
If InStr(astr, Chr(0)) = 1 Then
bstr = ""
Else
bstr = Left$(astr, InStr(astr, Chr(0)))
End If
If Trim(bstr) = "" Then
Combo1.AddItem "英语(美国)"
Else
Combo1.AddItem bstr
End If
Next i
End If
End Sub
Private Sub Text1_GotFocus()
If Combo1.ListCount > 0 Then
ActivateKeyboardLayout ActIme, 1
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -