在delphi中如何格式化U盘成fat16格式

dsq1980 2006-06-05 07:35:29
如题
...全文
705 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wudi_1982 2006-06-05
  • 打赏
  • 举报
回复
如果你直接调用SHFormatdrive,弹出了Windows磁盘格式化对话窗,可以选择格式化方式的。
wudi_1982 2006-06-05
  • 打赏
  • 举报
回复
好长时间没有用了,忘记了,你到google搜索一下SHFormatDrive,好多的。
dsq1980 2006-06-05
  • 打赏
  • 举报
回复
那FAT16和FAT32如何选
wudi_1982 2006-06-05
  • 打赏
  • 举报
回复
There is an API hidden away in Shell32.dll called SHFormatDrive, this brings up the standard format removable drive dialog. I stumbled across this in the borland.public.delphi.winapi newsgroup.

{implementation section}
..
..
const
SHFMT_ID_DEFAULT = $FFFF;
// Formating options
SHFMT_OPT_QUICKFORMAT = $0000;
SHFMT_OPT_FULL = $0001;
SHFMT_OPT_SYSONLY = $0002;
// Error codes
SHFMT_ERROR = $FFFFFFFF;
SHFMT_CANCEL = $FFFFFFFE;
SHFMT_NOFORMAT = $FFFFFFFD;

function SHFormatDrive(Handle: HWND; Drive, ID, Options: Word): LongInt;
stdcall; external 'shell32.dll' name 'SHFormatDrive'

procedure TForm1.btnFormatDiskClick(Sender: TObject);
var
retCode: LongInt;
begin
retCode:= SHFormatDrive(Handle, 0, SHFMT_ID_DEFAULT,
SHFMT_OPT_QUICKFORMAT);
if retCode < 0 then
ShowMessage('Could not format drive');
end;

end.
/////////////////////////////////////////
function SHFormatDrive(hWnd : HWND;Drive, fmtID, Options : WORD) : longint; stdcall; external 'shell32.dll';
function _DiskFormat( const Drive : Char ):string; //这个函数是非常危险的.
var
wDrive : WORD;
dtDrive : string;
formatretcode:longint;
begin
dtDrive := _DiskDriverType(Upcase(Drive));
if not _OK(dtDrive) then begin
result:=dtDrive+'(DiskFormat)'; exit;
end;
// if it's not a HDD or a FDD then raise an exception
if (not _Contain('可移动',dtDrive)) and (not _Contain('硬盘',dtDrive)) then
result := badresult+'无法格式化一个'+dtDrive
else begin// 进行格式化
wDrive := Ord( UpCase(Drive) ) - Ord( 'A' );
// SHFormatDrive 是一个没有公开的 API 函数调用
formatretcode:=SHFormatDrive( Application.Handle, wDrive, $ffff, 0);
if formatretcode=-1 then result:=badresult+'格式化程序已执行,在格式化中发生错误,返回代码:'+inttostr(formatretcode)
else if formatretcode=-2 then result:=badresult+'格式化程序已执行,用户放弃格式化驱动器:'+Drive
else if formatretcode=6 then result:='格式化程序已执行,完成驱动器:'+Drive+'的格式化'
else result:='格式化程序已执行,返回代码:'+inttostr(formatretcode);
end; // else
end;

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧