Option ExplicitPrivate 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 GetKeyboardLayoutName Lib "user32 " Alias "GetKeyboardLayoutNameA " (ByVal pwszKLID As String) 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 Declare Function ActivateKeyboardLayout Lib "user32 " (ByVal hkl As Long, ByVal flags As Long) As Long '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% '函数功能:获取当前输入法的名称 '功能描述: '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Function funGetNowIME() As String Dim lcurhk As Long Dim strDescription As String * 100 lcurhk = GetKeyboardLayout(0) If ImmIsIME(lcurhk) <> 1 Then funGetNowIME = "English(American) " Else ImmGetDescription lcurhk, strDescription, 100 funGetNowIME = TrimNull(strDescription) End If End Function '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% '函数功能: '功能描述: '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Public Function TrimNull(ByVal StrIn As String) As String Dim nul As Long
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 Private Sub Text1_GotFocus() If InStr(1, funGetNowIME, "ABC", vbTextCompare) <> 0 Then Text1.Locked = True '是智能ABC,禁止文本框输入 Else Text1.Locked = False '不是智能ABC,开启文本框输入 End If End Sub
Option ExplicitPrivate 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 GetKeyboardLayoutName Lib "user32 " Alias "GetKeyboardLayoutNameA " (ByVal pwszKLID As String) 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 Declare Function ActivateKeyboardLayout Lib "user32 " (ByVal hkl As Long, ByVal flags As Long) As Long
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'函数功能:获取当前输入法的名称
'功能描述:
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Function funGetNowIME() As String
Dim lcurhk As Long
Dim strDescription As String * 100
lcurhk = GetKeyboardLayout(0)
If ImmIsIME(lcurhk) <> 1 Then
funGetNowIME = "English(American) "
Else
ImmGetDescription lcurhk, strDescription, 100
funGetNowIME = TrimNull(strDescription)
End If
End Function
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'函数功能:
'功能描述:
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Public Function TrimNull(ByVal StrIn As String) As String
Dim nul As Long
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
Private Sub Text1_GotFocus()
If InStr(1, funGetNowIME, "ABC", vbTextCompare) <> 0 Then
Text1.Locked = True '是智能ABC,禁止文本框输入
Else
Text1.Locked = False '不是智能ABC,开启文本框输入
End If
End Sub