在VB中,某些控件具有输入焦点,却没有IMEMode属性,比如RichTextBox,为了方便在这些控件中控制输入法状态,俺编写了这个函数,代码如下:
Option Explicit '* ************************************************************** * '* 程序名称:modIME.bas '* 程序功能:用API控件输入法状态 '* 作者:lyserver '* 联系方式:http://blog.csdn.net/lyserver '* ************************************************************** * Private Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long 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 ActivateKeyboardLayout Lib "user32" (ByVal hkl As Long,ByVal flags As Long) As Long Private Const KLF_SETFORPROCESS = &H100 '打开或关闭中文输入法 Public Sub SetImeMode(bMode As Boolean) 'True打开、False关闭 Dim i As Long Dim hCurKB As Long Dim hKB() As Long,KBCount As Long hCurKB = GetKeyboardLayout(0) '获得当前输入法句柄 If CBool(ImmIsIME(hCurKB)) <> bMode Then KBCount = GetKeyboardLayoutList(0,ByVal 0&) ReDim hKB(KBCount - 1) GetKeyboardLayoutList KBCount,hKB(0) For i = 0 To KBCount - 1 If CBool(ImmIsIME(hKB(i))) = bMode Then ActivateKeyboardLayout hKB(i),KLF_SETFORPROCESS Exit For End If Next End If End Sub @H_403_4@