home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch19 / frmdraw.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  8.4 KB  |  231 lines

  1. VERSION 4.00
  2. Begin VB.Form frmDraw 
  3.    Caption         =   "Graphic Benchmarks"
  4.    ClientHeight    =   3270
  5.    ClientLeft      =   1080
  6.    ClientTop       =   2190
  7.    ClientWidth     =   5160
  8.    Height          =   3675
  9.    Left            =   1020
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3270
  12.    ScaleWidth      =   5160
  13.    Top             =   1845
  14.    Width           =   5280
  15.    Begin VB.CommandButton cmdExecute 
  16.       Caption         =   "Execute"
  17.       Height          =   375
  18.       Left            =   120
  19.       TabIndex        =   6
  20.       Top             =   1860
  21.       Width           =   1155
  22.    End
  23.    Begin VB.PictureBox Picture1 
  24.       Height          =   3135
  25.       Left            =   1500
  26.       ScaleHeight     =   207
  27.       ScaleMode       =   3  'Pixel
  28.       ScaleWidth      =   239
  29.       TabIndex        =   5
  30.       Top             =   60
  31.       Width           =   3615
  32.    End
  33.    Begin VB.CheckBox chkUseAPI 
  34.       Caption         =   "Use API"
  35.       Height          =   315
  36.       Left            =   180
  37.       TabIndex        =   4
  38.       Top             =   1500
  39.       Width           =   1095
  40.    End
  41.    Begin VB.OptionButton optSelect 
  42.       Caption         =   "Polygons"
  43.       Height          =   315
  44.       Index           =   3
  45.       Left            =   180
  46.       TabIndex        =   3
  47.       Top             =   1140
  48.       Width           =   1095
  49.    End
  50.    Begin VB.OptionButton optSelect 
  51.       Caption         =   "Circles"
  52.       Height          =   315
  53.       Index           =   2
  54.       Left            =   180
  55.       TabIndex        =   2
  56.       Top             =   780
  57.       Width           =   1095
  58.    End
  59.    Begin VB.OptionButton optSelect 
  60.       Caption         =   "Squares"
  61.       Height          =   315
  62.       Index           =   1
  63.       Left            =   180
  64.       TabIndex        =   1
  65.       Top             =   420
  66.       Width           =   1095
  67.    End
  68.    Begin VB.OptionButton optSelect 
  69.       Caption         =   "Lines"
  70.       Height          =   315
  71.       Index           =   0
  72.       Left            =   180
  73.       TabIndex        =   0
  74.       Top             =   60
  75.       Value           =   -1  'True
  76.       Width           =   1095
  77.    End
  78.    Begin VB.Label lblTicks 
  79.       Height          =   255
  80.       Left            =   120
  81.       TabIndex        =   9
  82.       Top             =   2880
  83.       Width           =   1275
  84.    End
  85.    Begin VB.Label lblKernel 
  86.       Height          =   255
  87.       Left            =   120
  88.       TabIndex        =   8
  89.       Top             =   2580
  90.       Width           =   1275
  91.    End
  92.    Begin VB.Label lblUser 
  93.       Height          =   255
  94.       Left            =   120
  95.       TabIndex        =   7
  96.       Top             =   2280
  97.       Width           =   1275
  98.    End
  99. Attribute VB_Name = "frmDraw"
  100. Attribute VB_Creatable = False
  101. Attribute VB_Exposed = False
  102. Option Explicit
  103. ' copyright 
  104.  1997 by Desaware Inc. All Rights Reserved
  105. Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
  106. Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
  107. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  108. Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
  109. Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  110. Private Declare Function Arc Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long
  111. Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Long, ByVal nCount As Long) As Long
  112. Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  113. Private Const NULL_BRUSH = 5
  114. Private Type POINTAPI
  115.         x As Long
  116.         y As Long
  117. End Type
  118. Dim CurrentOption%
  119. Private Const LOOPS = 200
  120. Dim bench As New dwBenchMark
  121. Dim starpoints(12) As Long
  122. Private Sub cmdExecute_Click()
  123.     Dim rgt&
  124.     Dim btm&
  125.     Dim current&
  126.     Dim loopcounter&
  127.     Dim pt As POINTAPI
  128.     Dim usedc&
  129.     Dim oldbrush&
  130.     Dim x&
  131.     Picture1.Cls
  132.     usedc = Picture1.hdc
  133.     bench.SetReference
  134.     For loopcounter = 1 To LOOPS
  135.         Select Case CurrentOption
  136.             Case 0
  137.                 rgt = Picture1.ScaleWidth
  138.                 btm = Picture1.ScaleHeight
  139.                 If chkUseAPI Then
  140.                     For current = 0 To rgt
  141.                         ' You'll see good performance here, but if you
  142.                         ' used picture1.hdc as a parameter, it would be
  143.                         ' slower than the VB code!  See chapter text
  144.                         Call MoveToEx(usedc, current&, 0, pt)
  145.                         Call LineTo(usedc, current, btm)
  146.                     Next current
  147.                 Else
  148.                     For current = 0 To rgt
  149.                         Picture1.Line (current, 0)-(current, btm)
  150.                     Next current
  151.                 End If
  152.             Case 1
  153.                 rgt = Picture1.ScaleWidth
  154.                 btm = Picture1.ScaleHeight
  155.                 If chkUseAPI Then
  156.                     oldbrush = SelectObject(usedc, GetStockObject(NULL_BRUSH))
  157.                     For current = 0 To rgt
  158.                         Call Rectangle(usedc, 0, 0, current, current)
  159.                     Next current
  160.                     ' Restore the original brush
  161.                     Call SelectObject(usedc, oldbrush)
  162.                 Else
  163.                     For current = 0 To rgt
  164.                         Picture1.Line (0, 0)-(current, current), , B
  165.                     Next current
  166.                 End If
  167.             Case 2
  168.                 rgt = Picture1.ScaleWidth
  169.                 btm = Picture1.ScaleHeight
  170.                 If chkUseAPI Then
  171.                     oldbrush = SelectObject(usedc, GetStockObject(NULL_BRUSH))
  172.                     For current = 0 To rgt
  173.                         Call Ellipse(usedc, -current, -current, current, current)
  174.                         ' Can perform the same task:
  175.                         ' Call Arc(usedc, -current, -current, current, current, 0, current, current, 0)
  176.                     Next current
  177.                     ' Restore the original brush
  178.                     Call SelectObject(usedc, oldbrush)
  179.                 Else
  180.                     For current = 0 To rgt
  181.                         Picture1.Circle (0, 0), current
  182.                     Next current
  183.                 End If
  184.             Case 3
  185.                 rgt = Picture1.ScaleWidth
  186.                 btm = Picture1.ScaleHeight
  187.                 If chkUseAPI Then
  188.                     oldbrush = SelectObject(usedc, GetStockObject(NULL_BRUSH))
  189.                     For current = 1 To rgt \ 4
  190.                         SetStarArray current
  191.                         Call Polygon(usedc, starpoints(0), 6)
  192.                     Next current
  193.                     ' Restore the original brush
  194.                     Call SelectObject(usedc, oldbrush)
  195.                 Else
  196.                     For current = 1 To rgt \ 4
  197.                         SetStarArray current
  198.                         For x = 0 To 8 Step 2
  199.                             Picture1.Line (starpoints(x), starpoints(x + 1))-(starpoints(x + 2), starpoints(x + 3))
  200.                         Next x
  201.                     Next current
  202.                 End If
  203.         End Select
  204.         Picture1.Cls
  205.     Next loopcounter
  206.     bench.SetMark
  207.     lblUser.Caption = "User: " & bench.GetuserDifferenceMS()
  208.     lblKernel.Caption = "Krnl: " & bench.GetkernelDifferenceMS()
  209.     lblTicks.Caption = "Tot: " & bench.GetTickDifference()
  210. End Sub
  211. Private Sub Form_Load()
  212. End Sub
  213. Private Sub optSelect_Click(Index As Integer)
  214.     CurrentOption = Index
  215. End Sub
  216. ' Load a scaled star into the starpoints array
  217. Public Sub SetStarArray(size As Long)
  218.     starpoints(0) = size * 2
  219.     starpoints(1) = 0
  220.     starpoints(2) = size
  221.     starpoints(3) = size * 4
  222.     starpoints(4) = size * 4
  223.     starpoints(5) = size
  224.     starpoints(6) = 0
  225.     starpoints(7) = size
  226.     starpoints(8) = size * 3
  227.     starpoints(9) = size * 4
  228.     starpoints(10) = starpoints(0)
  229.     starpoints(11) = starpoints(1)
  230. End Sub
  231.