X=0 | Y=0 | The upper left corner |
X=500 | Y=0 | The upper right corner |
X=500 | Y=500 | The bottom right corner |
X=0 | Y=500 | The Bottom left corner |
X=0 | Y=0 | The upper left corner again. As I mentioned - The shape must be closed |
Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI,
_
ByVal nCount As Long, ByVal nPolyFillMode As Long) As
Long
Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long,
_
ByVal hRgn As Long, ByVal bRedraw As Boolean) As
Long
Declare Function Polyline Lib "gdi32" (ByVal hdc As Long, lpPoint As
_
POINTAPI, ByVal nCount As Long) As Long
Public Type POINTAPI
X As
Long
Y As Long
End Type
Private Sub Command2_Click()
'shape your form with
your selected shape. replace the '4' below with the
'number of
points you have in your shape (in this exaple the last point is
Points(4).Y)
hRgn = CreatePolygonRgn(Points(1), 4,
1)
'if you want to shape other control, instead
of Form1, replace the "From1" below
'with the control's name. for
example, to shape Command1, uncomment
'the line below:
'Result =
SetWindowRgn(Command1.hWnd, hRgn, True)
Result =
SetWindowRgn(Form1.hWnd, hRgn, True)
End Sub
Private Sub Command1_Click()
'draw the shape on the
form, just to demonstrate how your form's shape will
be
Call Polyline(Form1.hdc, Points(1), 4)
End
Sub
Private Sub Command3_Click()
'restore the form to its
orginal shape
Result = SetWindowRgn(Form1.hWnd, 0,
True)
End Sub
Private Sub Form_Load()
'set the X and Y coordinates of every
corner.
'Points(1).X and Points(1).Y are the X and
Y coordinates of the
'first corner, and so on.
'note that to close the shape, the first point
(Points(1)) and the last
'point (Points(4)) are the same.
'If you add another points (Points(5).X and so on),
remember to update
'the line: Dim Points(1 To 4) As
POINTAPI to
'Dim Points(1 To 5) As POINTAPI
'and
the line: hRgn = CreatePolygonRgn(Points(1), 4, 1)
to
'hRgn = CreatePolygonRgn(Points(1), 5, 1)
Points(1).X =
500
Points(1).Y = 500
Points(2).X =
0
Points(2).Y = 0
Points(3).X =
1000
Points(3).Y = 0
Points(4).X =
500
Points(4).Y = 500
End Sub