Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse the PolyPolyline API function to draw lots of lines quickly
DescriptionThis example shows how to use the PolyPolyline API function to draw lots of lines quickly in Visual Basic 6.
Keywordspolyline, PolyPolyline, graphics
CategoriesGraphics
 
This program makes several spirals that start at the same point. It adds the points for each spiral to a single array of POINTAPIs. It also creates an array called counts that holds the number of points for each spiral. The PolyPolygon API function uses the counts array to decide which points belong to which polyline.
 
Private Sub Form_Load()
Const PI = 3.14159265
Const NUM_PLINES = 8
Const PTS_PER_PLINE = 30
Const Dtheta = 2 * PI / PTS_PER_PLINE

Dim cx As Single
Dim cy As Single
Dim num_points As Integer
Dim pts() As POINTAPI
Dim num_polylines As Integer
Dim counts() As Long
Dim i As Integer
Dim j As Integer
Dim theta As Single
Dim r As Single
Dim dr As Single

    ' Note that API drawing functions always work in pixels.
    picCanvas.ScaleMode = vbPixels
    picCanvas.AutoRedraw = True

    dr = picCanvas.ScaleWidth / 2 / PTS_PER_PLINE

    cx = picCanvas.ScaleWidth / 2
    cy = picCanvas.ScaleHeight / 2

    For i = 1 To NUM_PLINES
        ' Make a spiral.
        theta = i * 2 * PI / NUM_PLINES
        r = 0
        For j = 1 To PTS_PER_PLINE
            ' Make a point for this polyline.
            num_points = num_points + 1
            ReDim Preserve pts(1 To num_points)
            With pts(num_points)
                .X = cx + r * Cos(theta)
                .Y = cy + r * Sin(theta)
            End With
            theta = theta + Dtheta
            r = r + dr
        Next j

        ' Store the number of points in this polyline.
        num_polylines = num_polylines + 1
        ReDim Preserve counts(1 To num_polylines)
        counts(num_polylines) = PTS_PER_PLINE
    Next i

    ' Draw the polylines. pts is the array of points.
    ' counts is an array giving the number of points
    ' in each polyline. num_polylines is the number
    ' of entries in the counts array = the number of
    ' polylines to draw.
    PolyPolyline picCanvas.hdc, pts(1), counts(1), _
        num_polylines
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated