请帮助修改一下代码,谢谢!!!下面代码是取得鼠标滑轮信息的,求教把它改为当鼠标在Picture1范围内再起作用,谢谢!!!
Private Const PM_REMOVE = &H1Private HS As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
Private Const WM_MOUSEWHEEL = 522
Private Sub ProcessMessages()
Dim Message As Msg
Do While Not bCancel
' WaitMessage 'Wait For message and...
If PeekMessage(Message, Picture1.hWnd, WM_MOUSEWHEEL, WM_MOUSEWHEEL, PM_REMOVE) Then '...when the mousewheel is used...
If Message.wParam < 0 Then '...scroll up...
HS = HS + 1
Label1.Caption = Val(HS)
Else '... or scroll down
HS = HS - 1
Label1.Caption = Val(HS)
End If
End If
DoEvents
Loop
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
' Me.Print "Please use now mouse wheel to move this form."
Me.Show
ProcessMessages
End Sub
Private Sub Form_Unload(Cancel As Integer)
bCancel = True
End Sub
Private Const PM_REMOVE = &H1Private HS As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
Private Const WM_MOUSEWHEEL = 522
Private Sub ProcessMessages()
Dim Message As Msg
Do While Not bCancel
' WaitMessage 'Wait For message and...
If PeekMessage(Message, Picture1.hWnd, WM_MOUSEWHEEL, WM_MOUSEWHEEL, PM_REMOVE) Then '...when the mousewheel is used...
If Message.wParam < 0 Then '...scroll up...
HS = HS + 1
Label1.Caption = Val(HS)
Else '... or scroll down
HS = HS - 1
Label1.Caption = Val(HS)
End If
End If
DoEvents
Loop
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
' Me.Print "Please use now mouse wheel to move this form."
Me.Show
ProcessMessages
End Sub
Private Sub Form_Unload(Cancel As Integer)
bCancel = True
End Sub
Private OutPicture As Boolean
Private HS As LongPrivate Type POINTAPI
X As Long
Y As Long
End TypePrivate Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
Private Const WM_MOUSEWHEEL = 522Private Sub ProcessMessages()
Dim Message As Msg
Do While Not bCancel
' WaitMessage 'Wait For message and...
If PeekMessage(Message, Picture1.hWnd, WM_MOUSEWHEEL, WM_MOUSEWHEEL, PM_REMOVE) Then '...when the mousewheel is used...
If OutPicture = True Then GoTo 1
If Message.wParam < 0 Then '...scroll up...
HS = HS + 1
Label1.Caption = Val(HS)
Else '... or scroll down
HS = HS - 1
Label1.Caption = Val(HS)
End If
End If
DoEvents
1:
Loop
End SubPrivate Sub Form_Load()
OutPicture = True
Me.AutoRedraw = True
' Me.Print "Please use now mouse wheel to move this form."
Me.Show
ProcessMessages
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
OutPicture = True
End SubPrivate Sub Form_Unload(Cancel As Integer)
bCancel = True
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
OutPicture = False
End Sub跟你的对照一下就明白了