请问:
在程序的运行中,当插入U盘时,程序可以检查到U盘,并可以判断U盘的大小,及U盘的剩余空间
该怎样做
在程序的运行中,当插入U盘时,程序可以检查到U盘,并可以判断U盘的大小,及U盘的剩余空间
该怎样做
解决方案 »
- 关于机器码的问题(送分)
- 出错提问
- 封装 TMemo、TDBMemo 控件(支持 Ctrl+A 全选功能)
- 怎样制作控件
- 好像delphi比c++编译快很多。和vb接近。为什么?
- 关于delphi中的QReport控件!
- ADODataSet的CommandText字符串中的引号问题(在线等待)
- 找到hscrollbar但找不到cscrollbar,我装的是企业板D5,VSCROLLBAR哪里去了,
- dbengine和jetengine来压缩和修复数据库,参与者有分
- 谁有delphi汉化文件?那个几十k的东东没有用??
- USB(U盘问题) 第二个问题
- ADOConnection1的难题,请教高手指点谜经?在线等待~~~~~~~
我用32M 的U盘是正确的。
当我用128是读到的空间只有1/4 ,
你能把代码贴出来吗?(能在WIN 98 或 WINXP 使用)
剩余空间我是用MB 来表示的。
谢谢。
我可以再加一百分。
var lpFreeBytesAvailableToCaller : Integer;
var lpTotalNumberOfBytes: Integer;
var lpTotalNumberOfFreeBytes: Integer) : bool;
stdcall;
external kernel32
name 'GetDiskFreeSpaceExA';
procedure GetDiskSizeAvail(TheDrive : PChar;
var TotalBytes : double;
var TotalFree : double);
var
AvailToCall : integer;
TheSize : integer;
FreeAvail : integer;
begin
GetDiskFreeSpaceEx(TheDrive,
AvailToCall,
TheSize,
FreeAvail);
{$IFOPT Q+}
{$DEFINE TURNOVERFLOWON}
{$Q-}
{$ENDIF}
if TheSize >= 0 then
TotalBytes := TheSize else
if TheSize = -1 then begin
TotalBytes := $7FFFFFFF;
TotalBytes := TotalBytes * 2;
TotalBytes := TotalBytes + 1;
end else
begin
TotalBytes := $7FFFFFFF;
TotalBytes := TotalBytes + abs($7FFFFFFF - TheSize);
end;
if AvailToCall >= 0 then
TotalFree := AvailToCall else
if AvailToCall = -1 then begin
TotalFree := $7FFFFFFF;
TotalFree := TotalFree * 2;
TotalFree := TotalFree + 1;
end else
begin
TotalFree := $7FFFFFFF;
TotalFree := TotalFree + abs($7FFFFFFF - AvailToCall);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
TotalBytes : double;
TotalFree : double;
begin
GetDiskSizeAvail('C:\',
TotalBytes,
TotalFree);
ShowMessage(FloatToStr(TotalBytes));
ShowMessage(FloatToStr(TotalFree));
end;
var
i:integer;
DriveChar: Char;
DriveString:String;
DriveBits: set of 0..25;
Receive,send :String;
drivers :boolean;
sec, bytes1, space1,space2:longword;
byte1:double;
SectorsPerCluster: DWORD ; // for both D3 and D4
BytesPerSector : DWORD;
FreeClusters : DWORD;
TotalClusters : DWORD;
BytesPerCluster : Integer;
begin
Integer(DriveBits) := GetLogicalDrives;
for i:=0 to 25 do
begin
if not (i in DriveBits) then Continue;
DriveChar := Char(i + Ord('C'));
case GetDriveType(PChar(DriveChar + ':\')) of
DRIVE_REMOVABLE:
begin drivers := GetDiskFreeSpace(PAnsichar(DriveChar + ':\'), SectorsPerCluster,
BytesPerSector, FreeClusters, TotalClusters);
if drivers = true then
begin
BytesPerCluster := SectorsPerCluster * BytesPerSector;
send:= Floattostr(Roundto(BytesPerCluster * FreeClusters /1024/1024,-2))
end ;
showmessage((send));
end;
end;
end;
end;
以上是可以计算出剩余空间,
但在当插入U盘时,程序可以检查到U盘怎样做?
谢谢
再检测设备类型是不是可移动盘
再查移动盘盘符及容量(不过这些应该得系统分配完才好查)关注...
kellerlee的方法是可以检测,但程序的功能是当有U盘插入就立刻可以检测到。
当U盘插入时是不是有个什么事件触发了?
谢谢你的支持
发到[email protected]
谢谢你
初步测试是没问题的。
能把代码发给我吗?
谢谢
谢谢
extcsdn(Studing VB now)
谢谢,
到 http://community.csdn.net/Expert/topic/3108/3108794.xml?temp=.3003351
再多给你分