[FIELDSET][LEGEND]引自:1楼[/LEGEND]
您好,请参考以下代码。
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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 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 Const GWL_WNDPROC = (-4)
Public Const WM_MOUSEWHEEL = &H20A
Public lpWndProc As Long
Public Sub Hook(hwnd As Long)
lpWndProc = GetWindowLong(hwnd, GWL_WNDPROC) '获得原始窗口函数句柄
SetWindowLong hwnd, GWL_WNDPROC, AddressOf WindowProc '装载WM_MOUSEWHEEL消息的处理过程到窗口函数
End Sub
Public Sub UnHook(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, lpWndProc '御掉Hook,还原原始窗口函数
End Sub
Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'处理WM_MOUSEWHEEL消息的窗口函数
If uMsg = WM_MOUSEWHEEL Then
Dim wzDelta As Integer
wzDelta = HIWORD(wParam)
If Sgn(wzDelta) = 1 Then
DatabaseForm.DataGrid.Scroll 0, -1
Else
DatabaseForm.DataGrid.Scroll 0, 1
End If
End If
WindowProc = CallWindowProc(lpWndProc, hwnd, uMsg, wParam, lParam)
End Function
Public Function HIWORD(MsgParam As Long) As Integer
'取出32位值的高16位
HIWORD = (MsgParam And &HFFFF0000) \ &H10000
End Function
Form里的代码:
Private Sub Form_Load()
Hook DataGrid.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnHook DataGrid.hwnd
End Sub
[/FIELDSET]
回复:
我虽然学习研究了几年,但绝对不是高手,上面代码,我放到系统中,这要点击这个窗口,系统就立即关闭.不知是何原因.特请教.