|
-
Oct 7th, 2002, 05:47 AM
#1
Thread Starter
Hyperactive Member
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..
-
Oct 7th, 2002, 05:59 AM
#2
Member
Popupmenu seems to work for me. Did you specify the parent of the menu?
VB Code:
Select Case MsgCode
Case WM_RBUTTONDOWN
frm.PopupMenu frm.test
End Select
But
VB Code:
Select Case MsgCode
Case WM_RBUTTONDOWN
frm.PopupMenu test
End Select
crashed VB as you had described.
Sunny
* No trees were harmed in the making or sending of this message. However a great number of electrons were terribly inconvenienced.
-
Oct 7th, 2002, 11:34 AM
#3
Thread Starter
Hyperactive Member
oh ok, I was using it a different way
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|