Hi guys,
Dr Java Jo's ammendments made the code run correctly, but thanks for the other posts guys. Now im having a few probs turning it into a class and a function.
I need to be able to list the polygons in an array and delete them if the user requires it.
I currently have this code:
Class: clsPolygon
Option Explicit
Private Declare Function polygon Lib "gdi32" Alias "Polygon" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Const BLACKBRUSH = 4
Const ALTERNATE = 1
Const WINDING = 2
Module: modPolygon
Option Explicit
Private Type COORD
X As Long
Y As Long
End Type
Public Sub drawpolygon(ByVal lngX As Long, ByVal lngY As Long, ByVal dblHeight As Double, ByVal dblWidth As Double, ByVal lngHDC As Long)
Dim c As Double
Dim d As Double
Dim poly(1 To 4) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long
'No Verticies in Polygon
NumCoords = 4
c = Sqr(dblWidth ^ 2 / 2)
d = Sqr(dblHeight ^ 2 / 2)
poly(1).X = lngX
poly(1).Y = lngY
poly(2).X = poly(1).X + d
poly(2).Y = poly(1).Y + d
poly(3).X = poly(2).X - c
poly(3).Y = poly(2).Y + c
poly(4).X = poly(3).X - d
poly(4).Y = poly(3).Y - d
polygon lngHDC, poly(1), NumCoords
hBrush = GetStockObject(BLACKBRUSH)
hRgn = CreatePolygonRgn(poly(1), NumCoords, ALTERNATE)
DeleteObject hRgn
End Sub
Form1 Subs:
Option Explicit
Private lngX As Integer
Private lngY As Integer
Private Sub picPlan_Click()
Dim dblHeight As Double
Dim dblWidth As Double
dblHeight = 25
dblWidth = 40
Call drawpolygon(lngX, lngY, dblHeight, dblWidth, picPlan.hdc)
End Sub
Private Sub picPlan_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
lngX = X
lngY = Y
End Sub
Thanks Si