获取驱动器容量

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, FileCtrl;

type
  TForm1 = class(TForm)
    DriveComboBox1: TDriveComboBox;
    Edit1: TEdit;
    Label1: TLabel;
    Edit2: TEdit;
    Label2: TLabel;
    procedure DriveComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DriveComboBox1Change(Sender: TObject);
var
    driver:Char;
    userFreeBytes,totalBytes,freeBytes:Int64;
begin
  driver:=self.DriveComboBox1.Drive;
  GetDiskFreeSpaceEx(PChar(driver+':\'),userFreeBytes,totalBytes,@freeBytes);
  Edit1.Text:=Formatfloat('###,##0',totalBytes)+'字节';
  Edit2.Text:=Formatfloat('###,##0',freeBytes)+'字节';
end;

end.

 

FORM

object Form1: TForm1
  Left = 192
  Top = 107
  Width = 216
  Height = 155
  Caption = 'Drives'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 16
  object Label1: TLabel
    Left = 8
    Top = 56
    Width = 57
    Height = 16
    AutoSize = False
    Caption = #24635#23481#37327':'
  end
  object Label2: TLabel
    Left = 8
    Top = 88
    Width = 73
    Height = 16
    AutoSize = False
    Caption = #21097#20313#23481#37327':'
  end
  object DriveComboBox1: TDriveComboBox
    Left = 8
    Top = 16
    Width = 193
    Height = 22
    TabOrder = 0
    OnChange = DriveComboBox1Change
  end
  object Edit1: TEdit
    Left = 80
    Top = 48
    Width = 121
    Height = 24
    TabOrder = 1
    Text = 'Edit1'
  end
  object Edit2: TEdit
    Left = 80
    Top = 80
    Width = 121
    Height = 24
    TabOrder = 2
    Text = 'Edit1'
  end
end

posted @ 2009-03-27 23:31  DELPHI&.NET初学者[TECSOON WENDAY]  阅读(179)  评论(0编辑  收藏  举报