Results 1 to 8 of 8

Thread: Really Easy!!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843

    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!

  2. #2
    Megatron
    Guest
    To check with app has focus, use the GetForegroundWindow API.

  3. #3
    Megatron
    Guest
    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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    It sends me an error saying that the POINTAPI is not defined! I am sorry.. I am new at this!!!!!

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    oh.. I GET IT! Instead of private type... is public type!
    Thank you Megatron!!!!!!! I really needed this!

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    IT WORKS MAN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Ahem...... Thank you

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    How can I use this with the MSN Messenger instead of the calculator?

  8. #8
    Megatron
    Guest
    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
  •  



Click Here to Expand Forum to Full Width