Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Sub Form_Load()
preWndProc = SetWindowLong(Text1.hWnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call SetWindowLong(hWnd, GWL_WNDPROC, preWndProc)
End Sub
'模块代码
Option Explicit
Private Const WM_IME_CHAR As Long = &H286
Private Const WM_IME_COMPOSITION As Long = &H10F
Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public preWndProc As Long
Function WndProc(ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case msg
Case WM_IME_COMPOSITION
If lParam = 8127 Then
Debug.Print "输入中文了",
End If
Case WM_IME_CHAR
Debug.Print Chr$(wParam),
End Select
WndProc = CallWindowProc(preWndProc, hWnd, msg, wParam, lParam)
End Function