vb中如何得到当前的输入法?

igis 2004-12-24 02:00:36
vb中如何得到当前的输入法?
并且在vb中如何进行切换输入法?
...全文
245 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
laviewpbt 2004-12-24
  • 打赏
  • 举报
回复
在Form_load中加入
ActivateKeyboardLayout ActIme, 1
igis 2004-12-24
  • 打赏
  • 举报
回复
谢谢,各位,代码我已经试用过了,那是各种输入之间进行切换的,
实在是不好意思,我没有说清楚,我的主要目的是想不管他原来是什么输入法,现在都要将其切换到英文输入法状态下?
wwqna 2004-12-24
  • 打赏
  • 举报
回复
Public Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long
Public Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, lpList As Long) As Long
Public Declare Function GetKeyboardLayoutName Lib "user32" Alias "GetKeyboardLayoutNameA" (ByVal pwszKLID As String) 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 Declare Function ActivateKeyboardLayout Lib "user32" (ByVal HKL As Long, ByVal flags As Long) As Long

'得到当前的

Function GetCurIme() As String
Dim lcurhk As Long
Dim strDescription As String * 100
lcurhk = GetKeyboardLayout(0)
If ImmIsIME(lcurhk) <> 1 Then
GetCurIme = "English(American)"
Else
ImmGetDescription lcurhk, strDescription, 100
GetCurIme = TrimNull(strDescription)
End If
End Function
Public Function TrimNull(ByVal StrIn As String) As String
Dim nul As Long
'
' Truncate input string at first null.
' If no nulls, perform ordinary Trim.
'
nul = InStr(StrIn, vbNullChar)
Select Case nul
Case Is > 1
TrimNull = Left(StrIn, nul - 1)
Case 1
TrimNull = ""
Case 0
TrimNull = Trim(StrIn)
End Select
End Function

'切换就用activekeybodylayout
igis 2004-12-24
  • 打赏
  • 举报
回复
当然 不是中文版的,是英文的VB
AprilSong 2004-12-24
  • 打赏
  • 举报
回复
难道用的不是中文版?


IMEMode 属性

该属性返回或者设置的数值用来确定被选定的对象的 IME (Input Method Editor,输入方法编辑器)状态。

注意 只有 Visual Basic 的远东地区版本中才会出现该属性。
igis 2004-12-24
  • 打赏
  • 举报
回复
text没有IMEMode 属性啊??
AprilSong 2004-12-24
  • 打赏
  • 举报
回复
得到当前的不知道……

这是得所有的输入法列表~

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 ImmIsIME Lib "imm32.dll" (ByVal HKL As Long) As Long

Private Sub Form_Click()
Dim No As Long, i As Long
Dim hKB(24) As Long, bufflen As Long
Dim buff As String, RetStr As String, RetCount As Long
buff = String(255, 0)

No = GetKeyboardLayoutList(25, hKB(0))
For i = 1 To No
If ImmIsIME(hKB(i - 1)) = 1 Then
bufflen = 255
RetCount = ImmGetDescription(hKB(i - 1), buff, bufflen)
RetStr = Left(buff, RetCount)
Me.Print RetStr
Else
RetStr = "English(American)"
Me.Print RetStr
End If
Next
End Sub
laviewpbt 2004-12-24
  • 打赏
  • 举报
回复
Private Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, _
lpList As Long) As Long
Private Declare Function ActivateKeyboardLayout Lib "user32" (ByVal hkl As Long, ByVal _
flags 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
Dim la(1 To 16) As Long
Dim ActIme As Long
Private Sub Form_Load()
Dim astr As String * 256
Dim bstr As String
Dim X, hMem, i As Long
X = GetKeyboardLayoutList(32, la(1))
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 Combo1_Click()
ActIme = la(Combo1.ListIndex + 1)
ActivateKeyboardLayout ActIme, 1
End Sub
AprilSong 2004-12-24
  • 打赏
  • 举报
回复
切换输入法~

Private Sub Text1_GotFocus()
Text1.IMEMode = 1
End Sub

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧