关于文本框EN_CHANGE消息的问题
我想让文本框的内容发生改变时触发事件,但不想用Text1_Change事件,用API的SendMessage的EN_CHANGE如何实现呢?最好给个例子,谢谢啊。
[解决办法]
http://www.lihuasoft.net/article/show.php?id=348
你看看这个文档
[解决办法]
Edit给父窗体发送WM_COMMAND消息,在wParam参数中HIWORD包含EN_CHANGE消息。
这个消息属系统通知类消息,是用于接收的,不适于自己发送的。
[解决办法]
用SetWindowLong修改一个值,好像是(-4),把它改为自己的函数,不要的时候弄回去(SetWindowLong返回的就是原来的值。
[解决办法]
这个问题到底解决了吗?
以下代码为什么 只能捕捉到“VK_LEFT” 而不能捕捉“EN_CHANGE”事件
请大家帮忙解决一下,谢谢
Public Declare Function SetWindowLong Lib "user32 " Alias "SetWindowLongA " (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32 " 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 Declare Function SendMessage Lib "user32 " Alias "SendMessageA " (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_USER = &H400
Public Const GWL_WNDPROC = (-4)
Private OldWndProc As Long
Public Const VK_UP = &H101
Public Const VK_DOWN = &H100
Private Const VK_LEFT = &H25
Public Const EN_CHANGE = &H300
Private Const ENM_CHANGE = &H1
Private Const ENM_SELCHANGE = &H80000
Public Function WindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
' Debug.Print Msg, wParam, lParam
Select Case wParam
Case EN_CHANGE
Debug.Print "EN_CHANGE "
Case VK_LEFT
Debug.Print "VK_LEFT "
Case Else
' If Msg = WM_MYMESSAGE Then
' Debug.Print "自定义消息! "
' Exit Function
' End If
WindowProc = CallWindowProc(OldWndProc, hWnd, Msg, wParam, lParam)
End Select
End Function
Public Sub HookWindow(hWnd As Long)
OldWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnHook(hWnd As Long)
SetWindowLong hWnd, GWL_WNDPROC, OldWndProc
End Sub
------------------------
Option Explicit
Private Sub Form_load()
Call HookWindow(Text1.hWnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnHook(Text1.hWnd)
End Sub