PDA

Click to See Complete Forum and Search --> : Capture click on screen


Phailak
Dec 29th, 2000, 08:01 AM
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

YoungBuck
Dec 29th, 2000, 09:17 PM
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....



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

Phailak
Dec 30th, 2000, 02:49 PM
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