📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "在VB中切换中文输入法"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4590
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4590
StartUpPosition = 3 'Windows Default
Begin VB.ComboBox Combo1
Height = 300
Left = 120
TabIndex = 1
Top = 360
Width = 4335
End
Begin VB.TextBox Text1
Height = 2295
Left = 120
MultiLine = -1 'True
TabIndex = 0
Top = 720
Width = 4335
End
Begin VB.Label Label1
Caption = "请在列表中选择要使用的输入法"
Height = 255
Left = 120
TabIndex = 2
Top = 0
Width = 4335
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 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 Layout(1 To 16) As Long
Dim ActIme As Long
' 选择输入法
Private Sub Combo1_Click()
ActIme = Layout(Combo1.ListIndex + 1)
Text1.SetFocus
End Sub
' 初始装入输入法信息
Private Sub Form_Load()
Dim AStr As String * 256
Dim BStr As String
Dim x As Long
Dim hMem As Long
Dim i As Long
x = GetKeyboardLayoutList(32, Layout(1))
Combo1.Clear
If x Then
For i = 1 To x
ImmGetDescription Layout(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 + -