none
关于VB6.0中MSHFlexGrid控件实现鼠标滚动功能。那位老师有更好的方案! RRS feed

  • 问题

  • VB6.0对列表类控件不支持鼠标中键滚动功能。如果想实现这种功能就需要调用外部API函数来实现。
    下面的代码是我现在解决此功能的一个方法。虽然可以实现对数据表的滚动,可是效果太差,每次滚动的条数太多。
    原理:当向下滚动鼠标中键时向窗体发送下一页(Page Down)的按钮命令。当向上滚动鼠标中键时向窗体发送上一页(Page Up)的按钮命令。那么这样的话每次滚动一次鼠标中键MSHFlexGrid控件内的数据就会翻一页,
    现在我想实现当鼠标中键滚动时MSHFlexGrid控件内的数据滚动5行(或者读取控制面板的设置滚动条数来控制滚动条数)。
    '以下为模块代码
     '声明支持滚轮鼠标API---------------------------------
    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
    '声明支持滚轮鼠标API---------------------------------

    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 MSHFlexGrid1_GotFocus()
        Oldwinproc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
        SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf FlexScroll
    End Sub

    Private Sub MSHFlexGrid1_LostFocus()
        SetWindowLong Me.hwnd, GWL_WNDPROC, Oldwinproc
    End Sub
    以上为现在的解决方案。
    现在我想实现当鼠标中键滚动时MSHFlexGrid控件内的数据滚动5行(或者读取控制面板的设置滚动条数来控制滚动条数)。
    那位老师有更好的解决方案!


                                                                                                                                                           谢谢!


    时刻都在努力学习!
    2009年12月9日 2:19

答案

全部回复