[求助]问题出在什么地方?
VB6满足滚动条和鼠标滚轮事件的两个工程,用同样的模块,一个正常,一个就不正常,问题出在什么地方?请哪位高手指点一下:
同样的一个模块代码(原代码在附件中)
Option Explicit
Public Type POINTL
X As Long
Y As Long
End Type
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 Sub Hook(ByVal hWnd As Long)
lpPrevWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
Call SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, WHEEL_SCROLL_LINES, 0)
If WHEEL_SCROLL_LINES > Form1.VScroll1.max Then
WHEEL_SCROLL_LINES = Form1.VScroll1.max
End If
If WHEEL_SCROLL_LINES > form2.VScroll1.max Then
WHEEL_SCROLL_LINES = form2.VScroll1.max
End If
End Sub
Public Sub UnHook(ByVal hWnd As Long)
Dim lngReturnValue As Long
lngReturnValue = SetWindowLong(hWnd, GWL_WNDPROC, lpPrevWndProc)
End Sub
Function WindowProc(ByVal hw As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Dim pt As POINTL
Select Case uMsg
Case WM_MOUSEWHEEL
If wParam = -7864320 Then
If Form1.VScroll1.Value <= Form1.VScroll1.max - 100 Then
Form1.VScroll1.Value = Form1.VScroll1.Value + 100
Else
Form1.VScroll1.Value = Form1.VScroll1.max
End If
If form2.VScroll1.Value <= form2.VScroll1.max - 100 Then
form2.VScroll1.Value = form2.VScroll1.Value + 100
Else
form2.VScroll1.Value = form2.VScroll1.max
End If
ElseIf wParam = 7864320 Then
If Form1.VScroll1.Value >= 100 Then
Form1.VScroll1.Value = Form1.VScroll1.Value - 100
Else
Form1.VScroll1.Value = 0
End If
If form2.VScroll1.Value >= 100 Then
form2.VScroll1.Value = form2.VScroll1.Value - 100
Else
form2.VScroll1.Value = 0
End If
End If
Case Else
WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
End Select
End Function
Public Function HIWORD(LongIn As Long) As Integer
HIWORD = (LongIn And &HFFFF0000) \ &H10000
End Function
Public Function LOWORD(LongIn As Long) As Integer
LOWORD = LongIn And &HFFFF&
End Function