Click to See Complete Forum and Search --> : How do i trap a right-mouse click !!!!!!!!!1
kandan
Nov 22nd, 1999, 01:12 PM
hi,
how do i trap a right-mouse click on a form or button.
thanxxx..in adv
kandan
Keiko
Nov 22nd, 1999, 01:38 PM
Hi Kandan,
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MsgBox (Button)
End Sub
Left is 1
Right is 2
Does it help ?
Regards
kandan
Nov 22nd, 1999, 02:41 PM
hi keiko,
thanxx for ur help it works fine..but when i click in a command button r any other control it does'nt work.
any help??????????
kandan
Keiko
Nov 22nd, 1999, 03:28 PM
Hi Kandan,
Yes It does
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MsgBox (Button)
End Sub
You can try others.
Does it help ?
Regards
kandan
Nov 22nd, 1999, 03:54 PM
hi keiko,
i wanna generalized 1..in ur case i hav to write this event for each and every control that i put in the form which is ridiculus..so would u suggest me ?????????
thanxxxx
kandan
E-mail rg_kandan@usa.net
ICQ 52774533
Aaron Young
Nov 23rd, 1999, 11:28 AM
There are a Couple of methods you can use:
1. Use the GetAsyncKeyState API and a Timer Control..
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
'Make sure the focus is on this Form
If GetForegroundWindow <> hWnd Then Exit Sub
If GetAsyncKeyState(vbRightButton) Then
Caption = "Right Click"
'Do Your Form Global Event Here
Else
Caption = "Form1"
End If
End Sub
2. Create a Windows Hook on the Mouse..(Cleaner Method)..
In a Form..
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 Const WH_MOUSE = 7
Private lHook As Long
Private Sub Form_Load()
lHook = SetWindowsHookEx(WH_MOUSE, AddressOf GlobalRightMouseProc, App.hInstance, App.ThreadID)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnhookWindowsHookEx(lHook)
End Sub
In a Module..
Private Const WM_RBUTTONDOWN = &H204
Public Function GlobalRightMouseProc(ByVal iCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wParam = WM_RBUTTONDOWN And iCode = 0 Then
'Thread Global Right Click Event Goes In Here
End If
End Function
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.