Delphi Source Code
Search engine
HOME Components Tutorials Add Trick Links Contacts
ActiveX Components Database Files Forms Graphic Internet/Lan Math Miscellaneous Multimedia Printing Strings System Information Windows

Delphi source code for Windows >> Format a Win32 drive


Category: Windows
Title: Format a Win32 drive
Date added: 15.03.2006
Hits: 9562


{
  The SHFormatDrive API provides access to the Shell's format
  dialog box. This allows applications that want to format disks to bring
  up the same dialog box that the Shell uses for disk formatting.
}

const
  SHFMT_DRV_A = 0;
  SHFMT_DRV_B = 1;
  SHFMT_ID_DEFAULT = $FFFF;
  SHFMT_OPT_QUICKFORMAT = 0;
  SHFMT_OPT_FULLFORMAT = 1;
  SHFMT_OPT_SYSONLY = 2;
  SHFMT_ERROR = -1;
  SHFMT_CANCEL = -2;
  SHFMT_NOFORMAT = -3;

function SHFormatDrive(hWnd: HWND;
  Drive: Word;
  fmtID: Word;
  Options: Word): Longint
  stdcall; external 'Shell32.dll' Name 'SHFormatDrive';

procedure TForm1.Button1Click(Sender: TObject);
var
  FmtRes: Longint;
begin
  try
    FmtRes := ShFormatDrive(Handle,
      SHFMT_DRV_A,
      SHFMT_ID_DEFAULT,
      SHFMT_OPT_QUICKFORMAT);
    case FmtRes of
      SHFMT_ERROR: ShowMessage('Error formatting the drive');
      SHFMT_CANCEL: ShowMessage('User canceled formatting the drive');
      SHFMT_NOFORMAT: ShowMessage('No Format')
        else
          ShowMessage('Disk has been formatted!');
    end;
  except
    ShowMessage('Error Occured!');
  end;
end;
{
  Normally, if a diskette is not in the drive when SHFormatDrive is called,
  the system displays a critical error dialog box that asks the user
  to Abort, Retry, or Ignore.
  You can prevent the system from displaying this dialog box by calling
  the SetErrorMode API with SEM_FAILCRITICALERRORS.
}

var
  EMode: Word;
begin
  EMode := SetErrorMode(SEM_FAILCRITICALERRORS);
  SetErrorMode(EMode);
end;


Related Delphi Source Code:
Delphi Tricks
Delphi Tricks
For any problems or recommendations about Delphi Tricks site, please

feel free to contact us on that e-mail: support@delphitricks.com.
If you want to advertise on the site use that e-mail: advertise@delphitricks.com.

You can freely use or modify these Delphi source codes for non-commercial use. We are not responsible of any damages that can be caused by the utilisation of that source codes.

Copyright © 2006-2010 AVSoftware Company. All rights reserved.
Hide IP tricks