关于文本框EN_CHANGE消息的问题

HollyBeing 2007-06-19 05:16:57
我想让文本框的内容发生改变时触发事件,但不想用Text1_Change事件,用API的SendMessage的EN_CHANGE如何实现呢?最好给个例子,谢谢啊。
...全文
1376 6 点赞 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
热爱生活 2011-04-11
?/?、
  • 打赏
  • 举报
回复
gogc 2007-07-11
这个问题到底解决了吗?
以下代码为什么 只能捕捉到“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


  • 打赏
  • 举报
回复
knight_ice 2007-06-20
用SetWindowLong修改一个值,好像是(-4),把它改为自己的函数,不要的时候弄回去(SetWindowLong返回的就是原来的值。
  • 打赏
  • 举报
回复
homezj 2007-06-19
Edit给父窗体发送WM_COMMAND消息,在wParam参数中HIWORD包含EN_CHANGE消息。
这个消息属系统通知类消息,是用于接收的,不适于自己发送的。
  • 打赏
  • 举报
回复
HollyBeing 2007-06-19
谢谢关注,但这个地址没有相关内容。
  • 打赏
  • 举报
回复
孙小雄 2007-06-19
http://www.lihuasoft.net/article/show.php?id=348

你看看这个文档
  • 打赏
  • 举报
回复
相关推荐
发帖
API
创建于2007-09-28

1466

社区成员

VB API
申请成为版主
帖子事件
创建了帖子
2007-06-19 05:16
社区公告
暂无公告