hi,
how do i trap a right-mouse click on a form or button.
thanxxx..in adv
kandan
Printable View
hi,
how do i trap a right-mouse click on a form or button.
thanxxx..in adv
kandan
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
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
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
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 [email protected]
ICQ 52774533
There are a Couple of methods you can use:
1. Use the GetAsyncKeyState API and a Timer Control..
2. Create a Windows Hook on the Mouse..(Cleaner Method)..Code: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
In a Form..
In a Module..Code: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
Code: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
[email protected]
[email protected]