Results 1 to 2 of 2

Thread: Tough Q

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    184

    Post

    Hi,

    I need to simply tell the computer the area and have it tell me what object is there. how can I do that?

    .......................

    Something like this:

    Picture(12).left + picture(12).width + 200, Picture(12).top + picture(12).top + 300 = where picture(13) is.

    can I do that? thankyou!!

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    Add a Timer to your Form with some Controls..
    Code:
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    
    Private Sub Form_Load()
        Timer1.Interval = 100
    End Sub
    
    Private Sub Timer1_Timer()
        Dim tPOS As POINTAPI
        Call GetCursorPos(tPOS)
        Call ScreenToClient(hwnd, tPOS)
        Caption = FindObject(ScaleX(tPOS.x, vbPixels, vbTwips), ScaleY(tPOS.y, vbPixels, vbTwips))
    End Sub
    
    Private Function FindObject(ByVal x As Single, ByVal y As Single) As String
        On Error GoTo ObjErr
        For Each Control In Me
            If Control.Left <= x And Control.Top <= y Then
                If (Control.Left + Control.Width) >= x And (Control.Top + Control.Height) >= y Then
                    FindObject = Control.Name
                    Exit For
                End If
            End If
    ObjErr:
        Next
    End Function
    Run the Form and Point to some Controls to see its Name.

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

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