如和用API来实现格式化磁盘?(50分)

  • 主题发起人 主题发起人 mxt
  • 开始时间 开始时间
用甚麽API?<br><br>如果是Win32API,就用CreateFile和DeviceIOControl.<br>如果可以用ShellAPI,我可以给你一个控件,可以弹出标准的Format对话框.<br>如果用DOS/BIOS的API,我不会.<br>如果用POSIX的API,我也不会:)<br>
 
用CreateFile和DeviceIOControl.<br>可以举一个例吗?
 
这是非常复杂的过程,不是一句两句话能说得清楚的.你自己看Win32SDK的<br>文档,应该很明白.BBS上谁都不愿意输入长篇的论断,把SDK的文档贴出来又<br>没有任何用处.所以,BBS只能提供解决问题的方向,具体的步骤还要自己实验.<br><br>我也没有具体做过,但看SDK,应该涉及下面这些关键调用:<br><br>HANDLE h=CreateFile("////.//A:",...);<br>DeviceIoControl(h,FSCTL_LOCK_VOLUME,...);<br>DeviceIoControl(h,IOCTL_DISK_FORMAT_TRACKS,...);<br>DeviceIoControl(h,IOCTL_DISK_SET_PARTITION_INFO,...);<br>DeviceIoControl(h,FSCTL_UNLOCK_VOLUME,...);<br>CloseHandle(h);
 
有这样的windows api 吗?我不知道 &nbsp;:(<br>
 
去看看第5期的PC COMPUTING. 上面有介绍.<br>WWW: WWW.ZDNET.COM.CN
 
来自uddf的回答:<br>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.<br><br>{implementation section}<br>..<br>..<br>const<br>&nbsp; &nbsp; &nbsp; &nbsp; SHFMT_ID_DEFAULT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = $FFFF;<br>&nbsp; &nbsp; &nbsp; &nbsp; // Formating options<br>&nbsp; &nbsp; &nbsp; &nbsp; SHFMT_OPT_QUICKFORMAT &nbsp; = $0000;<br>&nbsp; &nbsp; &nbsp; &nbsp; SHFMT_OPT_FULL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= $0001;<br>&nbsp; &nbsp; &nbsp; &nbsp; SHFMT_OPT_SYSONLY &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = $0002;<br>&nbsp; &nbsp; &nbsp; &nbsp; // Error codes<br>&nbsp; &nbsp; &nbsp; &nbsp; SHFMT_ERROR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = $FFFFFFFF; <br>&nbsp; &nbsp; &nbsp; &nbsp; SHFMT_CANCEL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= $FFFFFFFE; <br>&nbsp; &nbsp; &nbsp; &nbsp; SHFMT_NOFORMAT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= $FFFFFFFD; <br><br>function SHFormatDrive(Handle: HWND; Drive, ID, Options: Word): LongInt;<br>&nbsp; &nbsp; &nbsp; &nbsp; stdcall; external 'shell32.dll' name 'SHFormatDrive'<br><br>procedure TForm1.btnFormatDiskClick(Sender: TObject);<br>var<br>&nbsp; &nbsp; &nbsp; &nbsp; retCode: LongInt;<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; retCode:= &nbsp; &nbsp; &nbsp; SHFormatDrive(Handle, 0, SHFMT_ID_DEFAULT,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SHFMT_OPT_QUICKFORMAT);<br>&nbsp; &nbsp; &nbsp; &nbsp; if retCode &lt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('Could not format drive');<br>end;<br><br>end.<br>
 
JJLEI朋友的应该可行。也可以结果问题了吧,问题太多了。
 
多人接受答案了。
 
后退
顶部