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 / ch13 / frmdisk.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  6.2 KB  |  194 lines

  1. VERSION 4.00
  2. Begin VB.Form frmDisk 
  3.    Caption         =   "Disk Analyzer"
  4.    ClientHeight    =   2790
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1515
  7.    ClientWidth     =   4215
  8.    Height          =   3195
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   2790
  12.    ScaleWidth      =   4215
  13.    Top             =   1170
  14.    Width           =   4335
  15.    Begin VB.DriveListBox Drive1 
  16.       Height          =   315
  17.       Left            =   120
  18.       TabIndex        =   0
  19.       Top             =   180
  20.       Width           =   3975
  21.    End
  22.    Begin VB.Label lblPercent 
  23.       BackColor       =   &H00FFFFFF&
  24.       BorderStyle     =   1  'Fixed Single
  25.       Height          =   315
  26.       Left            =   2160
  27.       TabIndex        =   14
  28.       Top             =   2340
  29.       Width           =   1935
  30.    End
  31.    Begin VB.Label Label1 
  32.       Alignment       =   1  'Right Justify
  33.       Caption         =   "Percent Free:"
  34.       Height          =   255
  35.       Index           =   6
  36.       Left            =   120
  37.       TabIndex        =   13
  38.       Top             =   2400
  39.       Width           =   1995
  40.    End
  41.    Begin VB.Label lblTotalBytes 
  42.       BackColor       =   &H00FFFFFF&
  43.       BorderStyle     =   1  'Fixed Single
  44.       Height          =   315
  45.       Left            =   2160
  46.       TabIndex        =   12
  47.       Top             =   2040
  48.       Width           =   1935
  49.    End
  50.    Begin VB.Label lblTotalFree 
  51.       BackColor       =   &H00FFFFFF&
  52.       BorderStyle     =   1  'Fixed Single
  53.       Height          =   315
  54.       Left            =   2160
  55.       TabIndex        =   11
  56.       Top             =   1740
  57.       Width           =   1935
  58.    End
  59.    Begin VB.Label Label1 
  60.       Alignment       =   1  'Right Justify
  61.       Caption         =   "Total Bytes:"
  62.       Height          =   255
  63.       Index           =   5
  64.       Left            =   120
  65.       TabIndex        =   10
  66.       Top             =   2100
  67.       Width           =   1995
  68.    End
  69.    Begin VB.Label Label1 
  70.       Alignment       =   1  'Right Justify
  71.       Caption         =   "Total free Bytes:"
  72.       Height          =   255
  73.       Index           =   4
  74.       Left            =   120
  75.       TabIndex        =   9
  76.       Top             =   1800
  77.       Width           =   1995
  78.    End
  79.    Begin VB.Label lblClusters 
  80.       BackColor       =   &H00FFFFFF&
  81.       BorderStyle     =   1  'Fixed Single
  82.       Height          =   315
  83.       Left            =   2160
  84.       TabIndex        =   8
  85.       Top             =   1440
  86.       Width           =   1935
  87.    End
  88.    Begin VB.Label lblFree 
  89.       BackColor       =   &H00FFFFFF&
  90.       BorderStyle     =   1  'Fixed Single
  91.       Height          =   315
  92.       Left            =   2160
  93.       TabIndex        =   7
  94.       Top             =   1140
  95.       Width           =   1935
  96.    End
  97.    Begin VB.Label lblBytes 
  98.       BackColor       =   &H00FFFFFF&
  99.       BorderStyle     =   1  'Fixed Single
  100.       Height          =   315
  101.       Left            =   2160
  102.       TabIndex        =   6
  103.       Top             =   840
  104.       Width           =   1935
  105.    End
  106.    Begin VB.Label lblSectors 
  107.       BackColor       =   &H00FFFFFF&
  108.       BorderStyle     =   1  'Fixed Single
  109.       Height          =   315
  110.       Left            =   2160
  111.       TabIndex        =   5
  112.       Top             =   540
  113.       Width           =   1935
  114.    End
  115.    Begin VB.Label Label1 
  116.       Alignment       =   1  'Right Justify
  117.       Caption         =   "Total number of clustors:"
  118.       Height          =   255
  119.       Index           =   3
  120.       Left            =   120
  121.       TabIndex        =   4
  122.       Top             =   1500
  123.       Width           =   1995
  124.    End
  125.    Begin VB.Label Label1 
  126.       Alignment       =   1  'Right Justify
  127.       Caption         =   "Number of free clusters:"
  128.       Height          =   255
  129.       Index           =   2
  130.       Left            =   120
  131.       TabIndex        =   3
  132.       Top             =   1200
  133.       Width           =   1995
  134.    End
  135.    Begin VB.Label Label1 
  136.       Alignment       =   1  'Right Justify
  137.       Caption         =   "Bytes per sector:"
  138.       Height          =   255
  139.       Index           =   1
  140.       Left            =   120
  141.       TabIndex        =   2
  142.       Top             =   900
  143.       Width           =   1995
  144.    End
  145.    Begin VB.Label Label1 
  146.       Alignment       =   1  'Right Justify
  147.       Caption         =   "Sectors per cluster:"
  148.       Height          =   255
  149.       Index           =   0
  150.       Left            =   120
  151.       TabIndex        =   1
  152.       Top             =   600
  153.       Width           =   1995
  154.    End
  155. Attribute VB_Name = "frmDisk"
  156. Attribute VB_Creatable = False
  157. Attribute VB_Exposed = False
  158. Option Explicit
  159. ' Copyright 
  160.  1997 by Desaware Inc. All Rights Reserved
  161. Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long
  162. Dim SectorsPerCluster&, BytesPerSector&, NumberOfFreeClustors&, TotalNumberOfClustors&
  163. Dim BytesFree&, BytesTotal&
  164. Dim PercentFree&
  165. Private Sub Drive1_Change()
  166.     DisplayResults
  167. End Sub
  168. Public Sub DisplayResults()
  169.     Dim dl&
  170.     Dim s$
  171.     Dim spaceloc%
  172.     Dim FreeBytes&, TotalBytes&
  173.     s$ = Drive1.Drive
  174.     ' Is there a space? Strip off the volume name if so
  175.     spaceloc = InStr(s$, " ")
  176.     If spaceloc > 0 Then
  177.         s$ = Left$(s$, spaceloc - 1)
  178.     End If
  179.     If Right$(s$, 1) <> "\" Then s$ = s$ & "\"
  180.     dl& = GetDiskFreeSpace(s$, SectorsPerCluster, BytesPerSector, NumberOfFreeClustors, TotalNumberOfClustors)
  181.     lblSectors = Format(SectorsPerCluster, "#,0")
  182.     lblBytes = Format(BytesPerSector, "#,0")
  183.     lblFree = Format(NumberOfFreeClustors, "#,0")
  184.     lblClusters = Format(TotalNumberOfClustors, "#,0")
  185.     TotalBytes = TotalNumberOfClustors * SectorsPerCluster * BytesPerSector
  186.     lblTotalBytes = Format(TotalBytes, "#,0")
  187.     FreeBytes = NumberOfFreeClustors * SectorsPerCluster * BytesPerSector
  188.     lblTotalFree = Format(FreeBytes, "#,0")
  189.     lblPercent = Format(FreeBytes / TotalBytes, "Percent")
  190. End Sub
  191. Private Sub Form_Load()
  192.     DisplayResults
  193. End Sub
  194.