Formatando disquete usando o Delphi

 

Veja nesta dica como implementar em seu programa a funcionalidade de formatar um disquete sem usar os recursos normais dos sistemas operacionais.

 

{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;