home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch12 / drives / drives.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-02-20  |  5.0 KB  |  153 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Drives and Directories"
  4.    ClientHeight    =   3600
  5.    ClientLeft      =   60
  6.    ClientTop       =   330
  7.    ClientWidth     =   6030
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3600
  10.    ScaleWidth      =   6030
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.Frame Frame1 
  13.       Caption         =   "Drive and Directories Information"
  14.       Height          =   2415
  15.       Left            =   120
  16.       TabIndex        =   1
  17.       Top             =   120
  18.       Width           =   5655
  19.       Begin VB.Label Label8 
  20.          Height          =   255
  21.          Left            =   1800
  22.          TabIndex        =   9
  23.          Top             =   1800
  24.          Width           =   2895
  25.       End
  26.       Begin VB.Label Label7 
  27.          Height          =   255
  28.          Left            =   1800
  29.          TabIndex        =   8
  30.          Top             =   1320
  31.          Width           =   2895
  32.       End
  33.       Begin VB.Label Label6 
  34.          Height          =   255
  35.          Left            =   1800
  36.          TabIndex        =   7
  37.          Top             =   840
  38.          Width           =   2775
  39.       End
  40.       Begin VB.Label Label5 
  41.          Height          =   255
  42.          Left            =   1800
  43.          TabIndex        =   6
  44.          Top             =   360
  45.          Width           =   3015
  46.       End
  47.       Begin VB.Label Label4 
  48.          Caption         =   "Windows Directory:"
  49.          Height          =   255
  50.          Left            =   120
  51.          TabIndex        =   5
  52.          Top             =   1800
  53.          Width           =   1695
  54.       End
  55.       Begin VB.Label Label3 
  56.          Caption         =   "Current Directory:"
  57.          Height          =   255
  58.          Left            =   120
  59.          TabIndex        =   4
  60.          Top             =   1320
  61.          Width           =   1455
  62.       End
  63.       Begin VB.Label Label2 
  64.          Caption         =   "Free Disk Space:"
  65.          Height          =   255
  66.          Left            =   120
  67.          TabIndex        =   3
  68.          Top             =   840
  69.          Width           =   1335
  70.       End
  71.       Begin VB.Label Label1 
  72.          Caption         =   "C Drive Type:"
  73.          Height          =   255
  74.          Left            =   120
  75.          TabIndex        =   2
  76.          Top             =   360
  77.          Width           =   1215
  78.       End
  79.    End
  80.    Begin VB.CommandButton Command1 
  81.       Caption         =   "Get Drive and Directories Info"
  82.       Height          =   495
  83.       Left            =   1440
  84.       TabIndex        =   0
  85.       Top             =   2880
  86.       Width           =   2415
  87.    End
  88. Attribute VB_Name = "Form1"
  89. Attribute VB_GlobalNameSpace = False
  90. Attribute VB_Creatable = False
  91. Attribute VB_PredeclaredId = True
  92. Attribute VB_Exposed = False
  93. Option Explicit
  94. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
  95.         (ByVal nDrive As String) As Long
  96. Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" _
  97.     (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, _
  98.     lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, _
  99.     lpTtoalNumberOfClusters As Long) As Long
  100. Private Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectoryA" _
  101.     (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
  102. Private Declare Function GetWindowsDirectory Lib "kernel32" _
  103.     Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  104. Const DRIVE_CDROM = 5
  105. Const DRIVE_FIXED = 3
  106. Const DRIVE_RAMDISK = 6
  107. Const DRIVE_REMOTE = 4
  108. Const DRIVE_REMOVABLE = 2
  109. Private Sub Command1_Click()
  110.     Dim driveType As Long
  111.     Dim freeSpace As Long
  112.     Dim Sectors As Long
  113.     Dim Bytes As Long
  114.     Dim freeClusters As Long
  115.     Dim totalClusters As Long
  116.     Dim retValue As Long
  117.     Dim buffer As String * 255
  118.     'Get drive type for c:
  119.     driveType = GetDriveType("c:\")
  120.     Select Case driveType
  121.         Case 0
  122.             Label5.Caption = "UNDETERMINED"
  123.             
  124.         Case 1
  125.             Label5.Caption = "NO ROOT"
  126.             
  127.         Case DRIVE_REMOVABLE
  128.             Label5.Caption = "REMOVABLE"
  129.             
  130.         Case DRIVE_FIXED
  131.             Label5.Caption = "FIXED"
  132.             
  133.         Case DRIVE_REMOTE
  134.             Label5.Caption = "REMOTE"
  135.             
  136.         Case DRIVE_CDROM
  137.             Label5.Caption = "CDROM"
  138.         
  139.         Case DRIVE_RAMDISK
  140.             Label5.Caption = "RAMDISK"
  141.             
  142.     End Select
  143.     'Get free space
  144.     retValue = GetDiskFreeSpace("c:\", Sectors, Bytes, freeClusters, totalClusters)
  145.     Label6.Caption = Sectors * Bytes * freeClusters
  146.     'Get current directory
  147.     retValue = GetCurrentDirectory(255, buffer)
  148.     Label7.Caption = buffer
  149.     'Get windows directory
  150.     retValue = GetWindowsDirectory(buffer, 255)
  151.     Label8.Caption = buffer
  152. End Sub
  153.