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
Declare Function SetWindowLong _
Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Declare Function SystemParametersInfo _
Lib "user32" Alias "SystemParametersInfoA" _
(ByVal uAction As Long, _
ByVal uParam As Long, _
lpvParam As Any, _
ByVal fuWinIni As Long) As Long
Declare Function ScreenToClient Lib "user32" _
(ByVal hWnd As Long, xyPoint As POINTL) As Long
Public Const GWL_WNDPROC = -4
Public Const SPI_GETWHEELSCROLLLINES = 104
Public Const WM_MOUSEWHEEL = &H20A
Public WHEEL_SCROLL_LINES As Long
Global lpPrevWndProc As Long
Public ScrollFrm As Form
Public Sub Hook(ByVal hWnd As Long, ByVal frm As Form)
'将屏幕坐标转换为Form1.窗口坐标
ScreenToClient ScrollFrm.hWnd, pt
With ScrollFrm.grdDataGrid
'判断坐标是否在Form1.grdDataGrid窗口内
If pt.X > .Left / Screen.TwipsPerPixelX And _
pt.X < (.Left + .Width) / Screen.TwipsPerPixelX And _
pt.Y > .Top / Screen.TwipsPerPixelY And _
pt.Y < (.Top + .Height) / Screen.TwipsPerPixelY Then
'滚动明细数据库
If wKeys = 16 Then
'滚动键按下,水平滚动grdDataGrid
If Sgn(wzDelta) = 1 Then
ScrollFrm.grdDataGrid.Scroll -1, 0
Else
ScrollFrm.grdDataGrid.Scroll 1, 0
End If
Else
If Sgn(wzDelta) = 1 Then
.Row = .Row - 1
Else
.Row = .Row + 1
End If
End If
Else
'鼠标不在grdDataGrid区域,滚动主数据库
With ScrollFrm.datPrimaryRS.Recordset
If Sgn(wzDelta) = 1 Then
If .BOF = False Then
.MovePrevious
If .BOF = True Then .MoveFirst
End If
Else
If .EOF = False Then
.MoveNext
If .EOF = True Then .MoveLast
End If
End If
End With
End If
End With
Else
WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
End If
Case Else
WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
End Select
可是我按照楼上给的代码用在我的DATAGRID中怎么会没有反应?代码如下:
以下代码写在模块里面
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 Function FlexScroll(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'支持滚轮的滚动 Yu 2004-5-10 15:33
Select Case wMsg