|
-
May 24th, 2001, 12:18 PM
#1
Thread Starter
Fanatic Member
Really Easy!!
I know this has to be somewhere here.... Normally I would look for it... but I have to go to work!
So... How can I detect when the event of mouse clic even though my form doesnt have the focus?
Also.... how can I know wich program has the focus?
THANK YOU>> THANK YOU!
-
May 24th, 2001, 01:08 PM
#2
To check with app has focus, use the GetForegroundWindow API.
-
May 24th, 2001, 01:13 PM
#3
And to detect a click, you need a combination of API's. This example will detect the click on Calculator.
Code:
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Timer1_Timer()
Dim PT As POINTAPI
Dim hWin As Long
Dim hCalc As Long
GetCursorPos PT
hWin = WindowFromPoint(PT.x, PT.y)
hCalc = FindWindow("SciCalc", "Calculator")
If hWin = hCalc Then
If GetAsyncKeyState(vbLeftButton) Then MsgBox "L Button pressed on Calc"
End If
End Sub
-
May 24th, 2001, 01:32 PM
#4
Thread Starter
Fanatic Member
It sends me an error saying that the POINTAPI is not defined! I am sorry.. I am new at this!!!!!
-
May 24th, 2001, 01:35 PM
#5
Thread Starter
Fanatic Member
oh.. I GET IT! Instead of private type... is public type! 
Thank you Megatron!!!!!!! I really needed this!
-
May 24th, 2001, 01:36 PM
#6
Thread Starter
Fanatic Member
IT WORKS MAN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Ahem...... Thank you
-
May 24th, 2001, 01:38 PM
#7
Thread Starter
Fanatic Member
How can I use this with the MSN Messenger instead of the calculator?
-
May 24th, 2001, 02:46 PM
#8
Your welcome.
To make it work with Messenger, use Spy++ to get the classname of messenger, then change this line as shown below.
Code:
hCalc = FindWindow("MessengerClass", vbNullString)
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
|