如何捕获Scrollbars事件

XinJW 2008-02-29 09:44:53
我现在用一第三方LISTVIEW控件,可是不支持鼠标的滚轮事件,网上搜一下资料,能实现,但是实现效果不是很好,下面的代码是让LISTVIEW滚动一页,如何实现滚动一行或者三行或者自定义几行而不是滚动一页,或者如何捕获Scrollbars事件?


Option Explicit

Public Const GWL_WNDPROC = (-4)
Public Const WM_COMMAND = &H111
Public Const WM_MBUTTONDOWN = &H207
Public Const WM_MBUTTONUP = &H208
Public Const WM_MOUSEWHEEL = &H20A

Public Oldwinproc As Long
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 GetWindowLong Lib "USER32" Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Function FlexScroll(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'支持鼠标动作
Select Case wMsg
Case WM_MOUSEWHEEL
Select Case wParam
Case -7864320 '向下
SendKeys "{PGDN}"

Case 7864320 '向上
SendKeys "{PGUP}"
End Select
End Select
FlexScroll = CallWindowProc(oldwinproc, hwnd, wMsg, wParam, lParam)
End Function



Private Sub lstCustom_GotFocus()
oldwinproc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf FlexScroll
End Sub

Private Sub lstCustom_LostFocus()
SetWindowLong Me.hwnd, GWL_WNDPROC, oldwinproc
End Sub
...全文
34 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
"无满意答案结贴"?

真是个火爆性子.

把论坛当实时IM来用了....真服.
回复
'支持鼠标动作
Select Case wMsg
Case WM_MOUSEWHEEL
Select Case wParam
Case -7864320 '向下
SendKeys "{DOWN}"

Case 7864320 '向上
SendKeys "{UP}"
End Select


试下.

不知道是不是支持,也不知道是什么控件,只能试下了
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2008-02-29 09:44
社区公告
暂无公告