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

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