home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch2 / Lines.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-03-22  |  4.5 KB  |  157 lines

  1. VERSION 5.00
  2. Begin VB.Form frmLines 
  3.    Caption         =   "Lines"
  4.    ClientHeight    =   4125
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1530
  7.    ClientWidth     =   6855
  8.    LinkTopic       =   "LineForm"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   4125
  11.    ScaleWidth      =   6855
  12.    Begin VB.CommandButton cmdDraw 
  13.       Caption         =   "Draw"
  14.       Default         =   -1  'True
  15.       Height          =   375
  16.       Left            =   3120
  17.       TabIndex        =   4
  18.       Top             =   3720
  19.       Width           =   615
  20.    End
  21.    Begin VB.PictureBox picLine 
  22.       AutoRedraw      =   -1  'True
  23.       Height          =   3375
  24.       Left            =   0
  25.       ScaleHeight     =   221
  26.       ScaleMode       =   3  'Pixel
  27.       ScaleWidth      =   221
  28.       TabIndex        =   1
  29.       Top             =   240
  30.       Width           =   3375
  31.    End
  32.    Begin VB.PictureBox picPolyline 
  33.       AutoRedraw      =   -1  'True
  34.       Height          =   3375
  35.       Left            =   3480
  36.       ScaleHeight     =   221
  37.       ScaleMode       =   3  'Pixel
  38.       ScaleWidth      =   221
  39.       TabIndex        =   0
  40.       Top             =   240
  41.       Width           =   3375
  42.    End
  43.    Begin VB.Label Label3 
  44.       Alignment       =   2  'Center
  45.       Caption         =   "Line"
  46.       Height          =   255
  47.       Index           =   1
  48.       Left            =   0
  49.       TabIndex        =   6
  50.       Top             =   0
  51.       Width           =   3375
  52.    End
  53.    Begin VB.Label Label3 
  54.       Alignment       =   2  'Center
  55.       Caption         =   "Polyline"
  56.       Height          =   255
  57.       Index           =   0
  58.       Left            =   3480
  59.       TabIndex        =   5
  60.       Top             =   0
  61.       Width           =   3375
  62.    End
  63.    Begin VB.Label lblLine 
  64.       BorderStyle     =   1  'Fixed Single
  65.       Height          =   255
  66.       Left            =   1080
  67.       TabIndex        =   3
  68.       Top             =   3720
  69.       Width           =   1215
  70.    End
  71.    Begin VB.Label lblPolyline 
  72.       BorderStyle     =   1  'Fixed Single
  73.       Height          =   255
  74.       Left            =   4560
  75.       TabIndex        =   2
  76.       Top             =   3720
  77.       Width           =   1215
  78.    End
  79. Attribute VB_Name = "frmLines"
  80. Attribute VB_GlobalNameSpace = False
  81. Attribute VB_Creatable = False
  82. Attribute VB_PredeclaredId = True
  83. Attribute VB_Exposed = False
  84. Option Explicit
  85. Private Declare Function Polyline Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
  86. Private Type POINTAPI
  87.         x As Long
  88.         y As Long
  89. End Type
  90. Private Points() As POINTAPI
  91. Private NumPoints As Integer
  92. ' Draw the lines 100 times.
  93. Private Sub cmdDraw_Click()
  94. Const NUM_TRIALS = 100
  95. Dim start_time As Single
  96. Dim stop_time As Single
  97. Dim i As Integer
  98. Dim trial As Integer
  99.     picPolyline.Cls
  100.     picLine.Cls
  101.     lblPolyline.Caption = ""
  102.     lblLine.Caption = ""
  103.     MousePointer = vbHourglass
  104.     DoEvents
  105.     start_time = Timer()
  106.     For trial = 1 To NUM_TRIALS
  107.         picLine.CurrentX = Points(1).x
  108.         picLine.CurrentY = Points(1).y
  109.         For i = 2 To NumPoints
  110.             picLine.Line -(Points(i).x, Points(i).y)
  111.         Next i
  112.     Next trial
  113.     stop_time = Timer()
  114.     picLine.Refresh
  115.     lblLine.Caption = Format$(stop_time - start_time, "0.0000")
  116.     DoEvents
  117.     start_time = Timer()
  118.     For trial = 1 To NUM_TRIALS
  119.         If Polyline(picPolyline.hdc, Points(1), NumPoints) = 0 Then Exit Sub
  120.     Next trial
  121.     stop_time = Timer()
  122.     picPolyline.Refresh
  123.     lblPolyline.Caption = Format$(stop_time - start_time, "0.0000")
  124.     MousePointer = vbDefault
  125. End Sub
  126. ' Create the points for the lines.
  127. Private Sub Form_Load()
  128. Dim i As Integer
  129. Dim small As Boolean
  130. Dim half As Integer
  131. Dim hgt As Integer
  132. Dim wid As Integer
  133.     NumPoints = picPolyline.ScaleWidth
  134.     ReDim Points(1 To NumPoints)
  135.     half = NumPoints \ 2
  136.     hgt = picPolyline.ScaleHeight
  137.     For i = 1 To half
  138.         Points(i).x = 2 * i
  139.         If small Then
  140.             Points(i).y = 0
  141.         Else
  142.             Points(i).y = hgt
  143.         End If
  144.         small = Not small
  145.     Next i
  146.     wid = picPolyline.ScaleWidth
  147.     For i = half + 1 To NumPoints
  148.         Points(i).y = 2 * (i - half)
  149.         If small Then
  150.             Points(i).x = 0
  151.         Else
  152.             Points(i).x = wid
  153.         End If
  154.         small = Not small
  155.     Next i
  156. End Sub
  157.