S
savetime
Unregistered / Unconfirmed
GUEST, unregistred user!
有个项目要对可移动磁盘(不是软盘)进行格式化,该磁盘采用FAT16格式,我不知道<br>在DELPHI中调用DOS命令FORMAT如何知道是否格式化成功(得到DOS错误返回码),<br>因此采用一个未公开的WINDOWS函数:SHFormatDrive,但调用后还得用户<br>按确定后才能执行操作。<br>希望大家能提供一个解决办法,DOS或WINDOWS都行,但要知道格式化错误码以便<br>在程序中控制流程。后附SHFormatDrive。<br><br>implementation<br><br>{$R *.dfm}<br><br>const<br> SHFMT_ID_DEFAULT = $FFFF;<br> // Formating options<br> SHFMT_OPT_QUICKFORMAT = $0000;<br> SHFMT_OPT_FULL = $0001;<br> SHFMT_OPT_SYSONLY = $0002;<br> // Error codes<br> SHFMT_ERROR = $FFFFFFFF; <br> SHFMT_CANCEL = $FFFFFFFE;<br> SHFMT_NOFORMAT = $FFFFFFFD;<br><br>function SHFormatDrive(Handle: HWND; Drive, ID, Options: Word): LongInt;<br> stdcall; external 'shell32.dll' name 'SHFormatDrive'<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> retCode: Longint;<br>begin<br> retCode := SHFormatDrive(Handle, 0, SHFMT_ID_DEFAULT,SHFMT_OPT_QUICKFORMAT);<br> if retCode < 0 then<br> ShowMessage('Could not format drive');<br>end;