Results 1 to 3 of 3

Thread: Capture click on screen

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    Montréal, Québec Canada
    Posts
    202
    Hi,
    I drew onto the form, a map of hexagons that fills the whole form. What I wish to do is to know which Hexagon the user clicked. I used a loop of createPolygon api to create the Hexagons and stored each region in a variable Hex(I).
    I also use the event Form_MouseMove to capture the location of the mouse when the Form_Click event is launched but I have no way to compare those coordinates with those of each hexagon region I created previously...
    Any one have any suggestions, maybe I'm going about this all wrong???

    Thanx

    Phailak

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Did you use the CreatePolygonRgn API call to store that handles of the hexagon's in the Hex() array that you speak of? If so you can use the PtInRegion API call to check if the user has clicked inside the polygon. Also you are going to need to use the Form_MouseDown event rather than the Form_Click event, here's some sample code....

    Code:
    Private Declare Function PtInRegion Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
     Dim iCt As Integer
     Dim lX As Long, lY As Long
     
        If Button = vbLeftButton Then ' if user clicked the left mouse button
            
            'Must convert coordinates from Twips to Pixels
            lX = x / Screen.TwipsPerPixelX
            lY = y / Screen.TwipsPerPixelY
            
            For iCt = LBound(hex) To UBound(hex) ' Loop through each region handle
            
                If Not PtInRegion(hex(iCt), lX, lY) = 0 Then ' Are coordinates within Hexagon
                
                    Debug.Print "Region Number " & iCt & " Selected!"
                    
                End If
                
            Next iCt
            
        End If
    
    End Sub
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    Montréal, Québec Canada
    Posts
    202
    Thanx,

    Didn't get a chance to try it yet, but seems logical to me, I had found a long run around that did not work effectivly, thanx again.

    Phailak

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