请教各位仁兄:如何取得本机所有硬盘的所有罗辑盘符?
http://www.delphi2007.net/DelphiBase/html/delphi_20061207001552249.html
如题多谢。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
nmg_tsTemp: TStringList;
function DriveAvail: Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.DriveAvail:Boolean;
var
r : LongWord;
Drives: array[0..128] of Char;
pDrive: PChar;
begin
Result:=False;
ZeroMemory(@Drives, SizeOf(Drives));
r := GetLogicalDriveStrings(SizeOf(Drives), Drives);
if r = 0 then Exit;
if r > SizeOf(Drives) then
begin
raise Exception.Create(SysErrorMessage(ERROR_OUTOFMEMORY));
end;
pDrive := Drives;
while pDrive^ <> #0 do
begin
if GetDriveType(pDrive) = DRIVE_FIXED then
begin
nmg_tsTemp.Add(StrPas(pDrive));
end;
inc(pDrive, 4);
end;
Result := True;
end;
procedure TForm1.btn1Click(Sender: TObject);
var
I: Integer;
begin
DriveAvail;
for I := nmg_tsTemp.Count - 1 downto 0 do
ShowMessage(nmg_tsTemp.Strings[i]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
nmg_tsTemp := TStringList.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
nmg_tsTemp.Free;
end;
end.
5分,楼主没"人性",呵呵,