Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Polygon OCX

Posted on 2002-04-24
Medium Priority
252 Views
I'm looking for something that will basically act like the Shape control that comes with Visual Basic, but will let me do more shapes than that.  Actually I only need to be able to do four-sided shapes where I can define where all four corners will be.  Is there anything out there that can help me?  Preferrably free, of course...

-Brian
0
Question by:pyrames
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 16

Expert Comment

ID: 6966813
see if this could help
' from www.allapi.net
Private Type COORD
x As Long
y As Long
End Type
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush 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 ALTERNATE = 1 ' ALTERNATE and WINDING are
Const WINDING = 2 ' constants for FillMode.
Const BLACKBRUSH = 4 ' Constant for brush type.
Private Sub Form_Paint()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim poly(1 To 3) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long
Me.Cls
' Number of vertices in polygon.
NumCoords = 3
' Set scalemode to pixels to set up points of triangle.
Me.ScaleMode = vbPixels
' Assign values to points.
poly(1).x = Form1.ScaleWidth / 2
poly(1).y = Form1.ScaleHeight / 2
poly(2).x = Form1.ScaleWidth / 4
poly(2).y = 3 * Form1.ScaleHeight / 4
poly(3).x = 3 * Form1.ScaleWidth / 4
poly(3).y = 3 * Form1.ScaleHeight / 4
' Polygon function creates unfilled polygon on screen.
' Remark FillRgn statement to see results.
Polygon Me.hdc, poly(1), NumCoords
' Gets stock black brush.
hBrush = GetStockObject(BLACKBRUSH)
' Creates region to fill with color.
hRgn = CreatePolygonRgn(poly(1), NumCoords, ALTERNATE)
' If the creation of the region was successful then color.
If hRgn Then FillRgn Me.hdc, hRgn, hBrush
DeleteObject hRgn
End Sub
Private Sub Form_Resize()
Form_Paint
End Sub

0

LVL 16

Accepted Solution

Richie_Simonetti earned 800 total points
ID: 6966821
' from same source:
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function CreatePolyPolygonRgn Lib "gdi32" (lpPoint As POINTAPI, lpPolyCounts As Long, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function InvertRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Const ALTERNATE = 1

Me.AutoRedraw = True
' Invert the points lying within a multi-polygonal region on window Form1.  The
' region is made up of a triangle and a diamond.  The triangle has vertices (25,25), (50,50),
' and (25,50).  The diamond has vertices (150,150), (200,200), (150,250), and (100,200).
Dim vertex(0 To 6) As POINTAPI ' holds vertices of each polygon
Dim numvertices(0 To 1) As Long  ' holds how many vertices belong to each polygon
Dim hRgn As Long  ' handle to the multi-polygonal region
Dim retval As Long  ' return value

' Load the vertices of the triangle into the vertex array.
vertex(0).x = 25: vertex(0).y = 25  ' 1st point: (25,25)
vertex(1).x = 50: vertex(1).y = 50  ' 2nd point: (50,50)
vertex(2).x = 25: vertex(2).y = 50  ' 3rd point: (25,50)
numvertices(0) = 3  ' three vertices for the triangle

' Load the vertices of the diamond into the vertex array.
vertex(3).x = 150: vertex(3).y = 150  ' 1st point: (150,150)
vertex(4).x = 200: vertex(4).y = 200  ' 2nd point: (200,200)
vertex(5).x = 150: vertex(5).y = 250  ' 3rd point: (150,250)
vertex(6).x = 100: vertex(6).y = 200  ' 4th point: (100,200)
numvertices(1) = 4  ' four vertices for the triangle

' Create the multi-polygonal region and get a handle to it.
hRgn = CreatePolyPolygonRgn(vertex(0), numvertices(0), 2, ALTERNATE)
' Invert the pixels within this region on Form1.
retval = InvertRgn(Me.hdc, hRgn)
' Delete the region to free up resources.
retval = DeleteObject(hRgn)
End Sub

0

LVL 49

Expert Comment

ID: 7670199
Hi pyrames,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

Accept Richie_Simonetti's comment(s) as an answer.

pyrames, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
0

LVL 1

Expert Comment

ID: 8092523
Comment from expert accepted as answer

Computer101
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
###### Suggested Courses
Course of the Month7 days, 22 hours left to enroll