VB Code:
  1. Option Explicit
  2. 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
  3. Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
  4. Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  5. Private MouseHookHandle As Long
  6.  
  7. Public Sub SetMouseHook()
  8.    Const WH_MOUSE = 7&
  9.    MouseHookHandle = SetWindowsHookEx(WH_MOUSE, AddressOf MyMouseHandler, App.hInstance, App.ThreadID)
  10.    End Sub
  11.  
  12. Public Sub ReleaseMouseHook()
  13.    If MouseHookHandle = 0 Then Exit Sub
  14.    UnhookWindowsHookEx MouseHookHandle
  15.    MouseHookHandle = 0
  16.    End Sub
  17.    
  18. Public Function MyMouseHandler(ByVal HookID As Long, ByVal MsgCode As Long, ByVal pMouseHookInfo As Long) As Long
  19. On Error Resume Next
  20.    Const WM_LBUTTONDOWN = &H201&  ' MouseDown - Left button
  21.    Const WM_MBUTTONDOWN = &H207&  '             Middle
  22.    Const WM_RBUTTONDOWN = &H204&  '             Right
  23.    
  24.    Const HC_ACTION = 0&
  25.    
  26.    If HookID <> HC_ACTION Then GoTo PassItOn
  27.    
  28.    Select Case MsgCode
  29.       Case WM_RBUTTONDOWN
  30.       MsgBox ""
  31.       End Select
  32.  
  33.  
  34. PassItOn:
  35.    '
  36.    ' allow mouse event to be passed on and processed normally
  37.    '
  38.    MyMouseHandler = CallNextHookEx(MouseHookHandle, HookID, MsgCode, pMouseHookInfo)
  39.    Exit Function
  40.    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..