Вопрос: Как работать с функцией GetVolumeInformation?
Ответ :
Создай пустой проект
замени в файлах все на это:
Код:
Unit1.cpp
=========================
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString Volume;
Volume.SetLength(256);
DWORD SerialNumber;
DWORD MaxComponentLength;
DWORD Flags;
AnsiString FileSystem;
FileSystem.SetLength(256);
if(GetVolumeInformation("C:\\", Volume.c_str(), Volume.Length (),
&SerialNumber, &MaxComponentLength, &Flags, FileSystem.c_str(), FileSystem.Length()))
{
Label1->Caption="C:\\";
Label2->Caption=Volume;
Label3->Caption=SerialNumber;
Label4->Caption=MaxComponentLength;
Label5->Caption=FileSystem;
}
}
//---------------------------------------------------------------------------
=============================
Unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
TLabel *Label5;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
==========================================
Unit1.dfm
object Form1: TForm1
Left = 192
Top = 107
Width = 120
Height = 203
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 16
Top = 48
Width = 32
Height = 13
Caption = 'Label1'
end
object Label2: TLabel
Left = 16
Top = 72
Width = 32
Height = 13
Caption = 'Label2'
end
object Label3: TLabel
Left = 16
Top = 96
Width = 32
Height = 13
Caption = 'Label3'
end
object Label4: TLabel
Left = 16
Top = 120
Width = 32
Height = 13
Caption = 'Label4'
end
object Label5: TLabel
Left = 24
Top = 144
Width = 32
Height = 13
Caption = 'Label5'
end
object Button1: TButton
Left = 0
Top = 0
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
end
=================================================
В *.dfm к сведению меняется так:
при видимой форме нажми ALT+f12
выдели там все и вставь это.
Пример реально работающий.
--------------------------------------------------------------------------------
(c) 2003 Borland X Portal
|