[滚轮消息求助]截获不到系统鼠标滚轮的滚动消息
用的是xp sp3和VB 6.0
鼠标移动的WM_MOUSEMOVE=&H200以及鼠标滚轮按下的消息&H207我都可以截获到
但鼠标滚轮滚动的WM_MOUSEWHEEL=&H20A我截获不到啊
!!!!如果截获到会弹出一个msgbox告诉我,并且我用timer控件一直在text1中显示截获的msg,我滑动滚轮时text1没有任何变化,但我按滚轮,移动鼠标等操作是有变化的,详见下面程序代码!!!!
程序如下(想要实现datagrid支持滚轮):
'-------bas模块部分代码
Option Explicit
Public Conn As ADODB.Connection
Public Rst As ADODB.Recordset
Public umsg1 As Long
'bas里的代码:(钩子得用GetWindowLong、SetWindowLong、CallWindowProc三个API,SetWindowLong要用到AddressOf回调自己的窗口函数,故要在工程里建立标准模块。好像有点废话呀)
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 = &H207
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消息的窗口函数
umsg1 = uMsg
If uMsg = WM_MOUSEWHEEL Then
MsgBox "nimei", vbInformation
Dim wzDelta As Integer
wzDelta = HIWORD(wParam)
If Sgn(wzDelta) = 1 Then
Form1.DataGrid.Scroll 0, -1
Else
Form1.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
'----------------form1窗体代码
Option Explicit
Private Sub Form_Load()
Set Conn = New ADODB.Connection
Set Rst = New ADODB.Recordset
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=D:\soken.mdb"
Rst.CursorLocation = adUseClient
Rst.Open "select * from 111209", "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=D:\soken.mdb", adOpenKeyset, adLockPessimistic
Set DataGrid.DataSource = Rst
Hook DataGrid.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnHook DataGrid.hwnd
End Sub
Private Sub Timer1_Timer()
Text1.Text = umsg1
End Sub
[解决办法]
晕,我知道了,datagrid数据就两行,滚动轴都没出来,所以滚轮没用啊-,-太囧了
[解决办法]
http://download.csdn.net/detail/veron_04/3629729
[解决办法]
http://download.csdn.net/detail/veron_04/3400339
[解决办法]
奇怪,又不行了……,现在有滚轮也不行了
[解决办法]