PDA

Click to See Complete Forum and Search --> : Really Easy!!


Andreex
May 24th, 2001, 12:18 PM
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!:p

Megatron
May 24th, 2001, 01:08 PM
To check with app has focus, use the GetForegroundWindow API.

Megatron
May 24th, 2001, 01:13 PM
And to detect a click, you need a combination of API's. This example will detect the click on Calculator.

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

Andreex
May 24th, 2001, 01:32 PM
It sends me an error saying that the POINTAPI is not defined! I am sorry.. I am new at this!!!!!:cool:

Andreex
May 24th, 2001, 01:35 PM
oh.. I GET IT! Instead of private type... is public type! :)
Thank you Megatron!!!!!!! I really needed this!

Andreex
May 24th, 2001, 01:36 PM
IT WORKS MAN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Ahem...... Thank you

Andreex
May 24th, 2001, 01:38 PM
How can I use this with the MSN Messenger instead of the calculator?

Megatron
May 24th, 2001, 02:46 PM
Your welcome.

To make it work with Messenger, use Spy++ to get the classname of messenger, then change this line as shown below.

hCalc = FindWindow("MessengerClass", vbNullString)