mouse hooking - help with code
VB Code:
Option Explicit
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private MouseHookHandle As Long
Public Sub SetMouseHook()
Const WH_MOUSE = 7&
MouseHookHandle = SetWindowsHookEx(WH_MOUSE, AddressOf MyMouseHandler, App.hInstance, App.ThreadID)
End Sub
Public Sub ReleaseMouseHook()
If MouseHookHandle = 0 Then Exit Sub
UnhookWindowsHookEx MouseHookHandle
MouseHookHandle = 0
End Sub
Public Function MyMouseHandler(ByVal HookID As Long, ByVal MsgCode As Long, ByVal pMouseHookInfo As Long) As Long
On Error Resume Next
Const WM_LBUTTONDOWN = &H201& ' MouseDown - Left button
Const WM_MBUTTONDOWN = &H207& ' Middle
Const WM_RBUTTONDOWN = &H204& ' Right
Const HC_ACTION = 0&
If HookID <> HC_ACTION Then GoTo PassItOn
Select Case MsgCode
Case WM_RBUTTONDOWN
MsgBox ""
End Select
PassItOn:
'
' allow mouse event to be passed on and processed normally
'
MyMouseHandler = CallNextHookEx(MouseHookHandle, HookID, MsgCode, pMouseHookInfo)
Exit Function
End Function
im using that to catch when the right mouse button is pressed..problem is, if I add just about anything else in there (other than some sort of msgbox) it just closes down VB and screws up.
Is there any way to make that just not return any type or action.. or better yet, pop up a menu? (regular poping up of a menu does not work there..it just crashes)
or have it perform some function or something..