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

  1. VERSION 5.00
  2. Begin VB.Form frmLineTo 
  3.    Caption         =   "LineTo"
  4.    ClientHeight    =   3585
  5.    ClientLeft      =   1620
  6.    ClientTop       =   1425
  7.    ClientWidth     =   5880
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   3585
  11.    ScaleWidth      =   5880
  12.    Begin VB.CommandButton cmdDraw 
  13.       Caption         =   "Draw"
  14.       Height          =   375
  15.       Left            =   2640
  16.       TabIndex        =   4
  17.       Top             =   3120
  18.       Width           =   615
  19.    End
  20.    Begin VB.PictureBox picLineTo 
  21.       AutoRedraw      =   -1  'True
  22.       Height          =   2775
  23.       Left            =   3000
  24.       ScaleHeight     =   181
  25.       ScaleMode       =   3  'Pixel
  26.       ScaleWidth      =   181
  27.       TabIndex        =   2
  28.       Top             =   240
  29.       Width           =   2775
  30.    End
  31.    Begin VB.PictureBox picLine 
  32.       AutoRedraw      =   -1  'True
  33.       Height          =   2775
  34.       Left            =   120
  35.       ScaleHeight     =   181
  36.       ScaleMode       =   3  'Pixel
  37.       ScaleWidth      =   181
  38.       TabIndex        =   0
  39.       Top             =   240
  40.       Width           =   2775
  41.    End
  42.    Begin VB.Label Label3 
  43.       Alignment       =   2  'Center
  44.       Caption         =   "MoveToEx and LineTo"
  45.       Height          =   255
  46.       Index           =   1
  47.       Left            =   3000
  48.       TabIndex        =   6
  49.       Top             =   0
  50.       Width           =   2775
  51.    End
  52.    Begin VB.Label Label3 
  53.       Alignment       =   2  'Center
  54.       Caption         =   "Line Method"
  55.       Height          =   255
  56.       Index           =   0
  57.       Left            =   120
  58.       TabIndex        =   5
  59.       Top             =   0
  60.       Width           =   2775
  61.    End
  62.    Begin VB.Label Label2 
  63.       BorderStyle     =   1  'Fixed Single
  64.       Height          =   255
  65.       Left            =   3840
  66.       TabIndex        =   3
  67.       Top             =   3120
  68.       Width           =   1095
  69.    End
  70.    Begin VB.Label Label1 
  71.       BorderStyle     =   1  'Fixed Single
  72.       Height          =   255
  73.       Left            =   960
  74.       TabIndex        =   1
  75.       Top             =   3120
  76.       Width           =   1095
  77.    End
  78. Attribute VB_Name = "frmLineTo"
  79. Attribute VB_GlobalNameSpace = False
  80. Attribute VB_Creatable = False
  81. Attribute VB_PredeclaredId = True
  82. Attribute VB_Exposed = False
  83. Option Explicit
  84. ' We declare the last argument to MoveToEx as Any so
  85. ' we can pass vbNullString to not get a return value.
  86. Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpPoint As Any) As Long
  87. Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
  88. ' Draw the lines.
  89. Private Sub cmdDraw_Click()
  90. Dim start_time As Single
  91. Dim stop_time As Single
  92. Dim x As Long
  93. Dim y As Long
  94. Dim hdc As Long
  95.     picLine.Cls
  96.     picLineTo.Cls
  97.     MousePointer = vbHourglass
  98.     DoEvents
  99.     start_time = Timer()
  100.     With picLine
  101.         For y = 0 To .ScaleHeight Step 4
  102.             .CurrentX = .ScaleLeft
  103.             .CurrentY = .ScaleTop + y - 1
  104.             For x = 0 To .ScaleWidth Step 4
  105.                 picLine.Line -Step(2, 0)
  106.                 picLine.Line -Step(0, 2)
  107.                 picLine.Line -Step(2, 0)
  108.                 picLine.Line -Step(0, -2)
  109.             Next x
  110.         Next y
  111.     End With
  112.     picLine.Refresh
  113.     stop_time = Timer()
  114.     Label1.Caption = Format$(stop_time - start_time, "0.0000")
  115.     DoEvents
  116.     start_time = Timer()
  117.     For y = 0 To picLineTo.ScaleHeight Step 4
  118.         MoveToEx picLineTo.hdc, 0, y, vbNullString
  119.         For x = 0 To picLineTo.ScaleWidth Step 4
  120.             LineTo picLineTo.hdc, x + 2, y
  121.             LineTo picLineTo.hdc, x + 2, y + 2
  122.             LineTo picLineTo.hdc, x + 4, y + 2
  123.             LineTo picLineTo.hdc, x + 4, y
  124.         Next x
  125.     Next y
  126.     picLineTo.Refresh
  127.     stop_time = Timer()
  128.     Label2.Caption = Format$(stop_time - start_time, "0.0000")
  129.     MousePointer = vbDefault
  130. End Sub
  131.