我想用VB寫一支偵測滑鼠所有動作的程式,滑鼠其他動作(左鍵、右鍵、中間鍵、移動)VB都有內定函數可以用,但是中間滾輪的話就沒有,想請問一下,該如何下手呢?謝謝!!
2005-11-22 07:31:52 · 2 個解答 · 發問者 藍 2 in 電腦與網際網路 ➔ 程式設計
'以下寫在模組
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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_MOUSEWHEEL = &H20A
Public PrevWndProc As Long
Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_MOUSEWHEEL Then
Form1.Print wParam '寫下你要的動作
Else
WndProc = CallWindowProc(PrevWndProc, hwnd, Msg, wParam, lParam)
End If
End Function
'----------------------------------------------------------------------
'以下寫在表單
Private Sub Form_Load()
PrevWndProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf WndProc
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetWindowLong Me.hwnd, GWL_WNDPROC, PrevWndProc
End Sub
2005-11-22 08:35:00 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
請使用滑鼠廠商所提供之驅動程式
把驅動程式的 DLL 加入到你的VB程式內去呼叫即可
一般都是這樣的作法
2005-11-22 07:42:32 · answer #2 · answered by Anonymous · 0⤊ 0⤋