Solved

Polygon OCX

Posted on 2002-04-24
4
230 Views
Last Modified: 2012-08-14
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...

Thanks in advance!
-Brian
0
Comment
Question by:pyrames
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
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

by:
Richie_Simonetti earned 200 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
Private Sub Form_Load()
    '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

by:DanRollins
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

by:Computer101
ID: 8092523
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now