VB中 ComboBox控件如何屏蔽鼠标滚轮事件
我在使用ComboBox控件时,先选择ComboBox控件中的某一项,然后可以滑动鼠标滚轮改变选择的项,现在我想屏蔽掉这功能...
我在使用ComboBox控件时,先选择ComboBox控件中的某一项,然后可以滑动鼠标滚轮改变选择的项,现在我想屏蔽掉这功能
展开
2个回答
2014-08-22
展开全部
'模块中:
Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private 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
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_MOUSEWHEEL As Long = &H20A
Private Const GWL_WNDPROC = (-4)
Private PrevWndProc As Long
Public Function SubWndProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case msg '在这里进行过滤.如果知道其他的消息,也可以在这里过滤.
Case WM_MOUSEWHEEL
SubWndProc = 1 '屏蔽掉
Exit Function
End Select
SubWndProc = CallWindowProc(PrevWndProc, hwnd, msg, wParam, lParam) '其它消息不管
End Function
Public Sub CallHook(ByVal hwnd As Long)
PrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf SubWndProc)
End Sub
Public Sub CallUnhook(ByVal hwnd As Long)
Dim lngReturnValue As Long
lngReturnValue = SetWindowLong(hwnd, GWL_WNDPROC, PrevWndProc)
End Sub
'窗体中:
Private Sub Form_Load()
Dim i As Integer
CallHook Combo1.hwnd
For i = 1 To 10
Combo1.AddItem i
Next
End Sub
Private Sub Form_Unload(Cancel As Integer)
CallUnhook Combo1.hwnd
End Sub
Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private 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
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_MOUSEWHEEL As Long = &H20A
Private Const GWL_WNDPROC = (-4)
Private PrevWndProc As Long
Public Function SubWndProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case msg '在这里进行过滤.如果知道其他的消息,也可以在这里过滤.
Case WM_MOUSEWHEEL
SubWndProc = 1 '屏蔽掉
Exit Function
End Select
SubWndProc = CallWindowProc(PrevWndProc, hwnd, msg, wParam, lParam) '其它消息不管
End Function
Public Sub CallHook(ByVal hwnd As Long)
PrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf SubWndProc)
End Sub
Public Sub CallUnhook(ByVal hwnd As Long)
Dim lngReturnValue As Long
lngReturnValue = SetWindowLong(hwnd, GWL_WNDPROC, PrevWndProc)
End Sub
'窗体中:
Private Sub Form_Load()
Dim i As Integer
CallHook Combo1.hwnd
For i = 1 To 10
Combo1.AddItem i
Next
End Sub
Private Sub Form_Unload(Cancel As Integer)
CallUnhook Combo1.hwnd
End Sub
更多追问追答
追问
能具体说下这代码的执行吗?
追答
这段是win消息hook,通过截获windows的滚轮消息,来屏蔽。
具体什么是hook,在百度搜索,就知道了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询