|
-
Nov 22nd, 1999, 02:12 PM
#1
Thread Starter
Member
hi,
how do i trap a right-mouse click on a form or button.
thanxxx..in adv
kandan
-
Nov 22nd, 1999, 02:38 PM
#2
Addicted Member
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
-
Nov 22nd, 1999, 03:41 PM
#3
Thread Starter
Member
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
-
Nov 22nd, 1999, 04:28 PM
#4
Addicted Member
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
-
Nov 22nd, 1999, 04:54 PM
#5
Thread Starter
Member
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
-
Nov 23rd, 1999, 12:28 PM
#6
There are a Couple of methods you can use:
1. Use the GetAsyncKeyState API and a Timer Control..
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
2. Create a Windows Hook on the Mouse..(Cleaner Method)..
In a Form..
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
In a Module..
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]
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
|