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 / samples5 / ch19 / apicheck.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-02-16  |  4.8 KB  |  158 lines

  1. VERSION 5.00
  2. Begin VB.Form frmAPICheck 
  3.    Caption         =   "API Calling Test"
  4.    ClientHeight    =   2790
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1485
  7.    ClientWidth     =   4440
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   2790
  11.    ScaleWidth      =   4440
  12.    Begin VB.CommandButton cmdCallDLL2 
  13.       Caption         =   "Call In DLL Server 2"
  14.       Height          =   555
  15.       Left            =   180
  16.       TabIndex        =   5
  17.       Top             =   2040
  18.       Width           =   1755
  19.    End
  20.    Begin VB.CommandButton cmdCallDLL 
  21.       Caption         =   "Call In DLL Server"
  22.       Height          =   555
  23.       Left            =   180
  24.       TabIndex        =   4
  25.       Top             =   1440
  26.       Width           =   1755
  27.    End
  28.    Begin VB.CommandButton cmdInFunction 
  29.       Caption         =   "Call In Function"
  30.       Height          =   555
  31.       Left            =   180
  32.       TabIndex        =   3
  33.       Top             =   840
  34.       Width           =   1755
  35.    End
  36.    Begin VB.CommandButton cmdDirect 
  37.       Caption         =   "Call Directly"
  38.       Height          =   555
  39.       Left            =   180
  40.       TabIndex        =   0
  41.       Top             =   240
  42.       Width           =   1755
  43.    End
  44.    Begin VB.Label lblKernel 
  45.       Height          =   255
  46.       Left            =   2220
  47.       TabIndex        =   6
  48.       Top             =   660
  49.       Width           =   2115
  50.    End
  51.    Begin VB.Label lblTicks 
  52.       Height          =   255
  53.       Left            =   2220
  54.       TabIndex        =   2
  55.       Top             =   1020
  56.       Width           =   2115
  57.    End
  58.    Begin VB.Label lblUser 
  59.       Height          =   255
  60.       Left            =   2220
  61.       TabIndex        =   1
  62.       Top             =   300
  63.       Width           =   2115
  64.    End
  65. Attribute VB_Name = "frmAPICheck"
  66. Attribute VB_GlobalNameSpace = False
  67. Attribute VB_Creatable = False
  68. Attribute VB_PredeclaredId = True
  69. Attribute VB_Exposed = False
  70. Option Explicit
  71. ' Copyright 
  72.  1997 by Desaware Inc. All Rights Reserved
  73. Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
  74. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  75. Dim r As New dwBenchMark
  76. Private Sub cmdCallDLL_Click()
  77.     Dim marker As New dwBenchMark
  78.     Dim wintext As Object
  79.     Dim res$
  80.     Dim counter&
  81.     Dim usewnd&
  82.     usewnd = hwnd
  83.     Set wintext = CreateObject("tstWindowText.App")
  84.     Screen.MousePointer = vbHourglass
  85.     marker.SetReference
  86.     For counter = 1 To 10000
  87.         res$ = wintext.GetWindowText(usewnd)
  88.     Next counter
  89.     marker.SetMark
  90.     Screen.MousePointer = vbDefault
  91.     ShowDifference marker
  92. End Sub
  93. Private Sub cmdCallDLL2_Click()
  94.     Dim marker As New dwBenchMark
  95.     Dim wintext As tstWindowText.App
  96.     Dim res$
  97.     Dim counter&
  98.     Dim usewnd&
  99.     usewnd = hwnd
  100.     Set wintext = CreateObject("tstWindowText.App")
  101.     Screen.MousePointer = vbHourglass
  102.     marker.SetReference
  103.     With wintext
  104.         For counter = 1 To 10000
  105.             res$ = .GetWindowText(usewnd)
  106.         Next counter
  107.     End With
  108.     marker.SetMark
  109.     Screen.MousePointer = vbDefault
  110.     ShowDifference marker
  111. End Sub
  112. Private Sub cmdDirect_Click()
  113.     Dim textlen As Long
  114.     Dim usewnd As Long
  115.     Dim counter As Long
  116.     Dim marker As New dwBenchMark
  117.     Dim res$
  118.     usewnd = hwnd
  119.     textlen = GetWindowTextLength(usewnd) + 1
  120.     res$ = String$(textlen + 1, 0)
  121.     Screen.MousePointer = vbHourglass
  122.     marker.SetReference
  123.     For counter = 1 To 10000
  124.         Call GetWindowText(usewnd, res$, textlen)
  125.     Next counter
  126.     marker.SetMark
  127.     Screen.MousePointer = vbDefault
  128.     ShowDifference marker
  129. End Sub
  130. Public Sub ShowDifference(marker As Object)
  131.     lblTicks.Caption = "Ticks = " & marker.GetTickDifference() & " ms"
  132.     lblUser.Caption = "User time = " & marker.GetuserDifferenceMS() & " ms"
  133.     lblKernel.Caption = "Kernel time = " & marker.GetkernelDifferenceMS() & " ms"
  134. End Sub
  135. Public Function InternalGetWindowText(ByVal usewnd As Long) As String
  136.     Dim textlen As Long
  137.     Dim res$
  138.     textlen = GetWindowTextLength(usewnd) + 1
  139.     res$ = String$(textlen + 1, 0)
  140.     Call GetWindowText(usewnd, res$, textlen)
  141.     InternalGetWindowText = res$
  142. End Function
  143. Private Sub cmdInFunction_Click()
  144.     Dim marker As New dwBenchMark
  145.     Dim res$
  146.     Dim counter&
  147.     Dim usewnd&
  148.     usewnd = hwnd
  149.     Screen.MousePointer = vbHourglass
  150.     marker.SetReference
  151.     For counter = 1 To 10000
  152.         res$ = InternalGetWindowText(usewnd)
  153.     Next counter
  154.     marker.SetMark
  155.     Screen.MousePointer = vbDefault
  156.     ShowDifference marker
  157. End Sub
  158.