⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 <<C++Builder 6实用编程100例>>随书光盘
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include <mmsystem.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
        char c;
        String S;
        int type;
        for(c='A';c<='Z';c++)
        {
                S=String(c)+":";
                type=GetDriveType(S.c_str());
                if(type==DRIVE_FIXED)
                        ComboBox1->Items->Add(S);
        }
        if(ComboBox1->Items->Count==0)
                ComboBox1->Items->Add("抱歉,没有找到硬盘。");
        else
        {
                ComboBox1->ItemIndex=0;
                DWORD sector,byte,cluster,free;
                long totalspace,freespace;
                GetDiskFreeSpace("C:\\",&sector,&byte,&free,&cluster);
                totalspace=long(cluster)*long(byte)/1024/1024*long(sector);
                freespace=int(free)*int(byte)/1024/1024*int(sector);
                Series1->Add(totalspace-freespace,"已用空间",clBlue);
                Series1->Add(freespace,"可用空间",clPurple);
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
        DWORD sector,byte,cluster,free;
        long totalspace,freespace;
        String path;
        path=ComboBox1->Text+"\\";
        GetDiskFreeSpace(path.c_str(),&sector,&byte,&free,&cluster);
        totalspace=long(cluster)*long(byte)/1024/1024*long(sector);
        freespace=int(free)*int(byte)/1024/1024*int(sector);
        Series1->Clear();
        Series1->Add(totalspace-freespace,"已用空间",clBlue);
        Series1->Add(freespace,"可用空间",clPurple);
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -