1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
   | unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    GroupBox1: TGroupBox;
    RadioButtonDriveB: TRadioButton;
    RadioButtonDriveA: TRadioButton;
    GroupBox2: TGroupBox;
    RadioButtonRapide: TRadioButton;
    RadioButtonComplet: TRadioButton;
    RadioButtonCopierSystem: TRadioButton;
    procedure Button1Click(Sender: TObject);
  private
    { Déclarations privées }
  public
 
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.DFM}
const SHFMT_DRV_A = 0;
const SHFMT_DRV_B = 1;
 
const SHFMT_ID_DEFAULT = $FFFF;
 
const SHFMT_OPT_QUICKFORMAT = 0;
const SHFMT_OPT_FULLFORMAT  = 1;
const SHFMT_OPT_SYSONLY     = 2;
 
const SHFMT_ERROR    = -1;
const SHFMT_CANCEL   = -2;
const SHFMT_NOFORMAT = -3;
 
 
function SHFormatDrive(hWnd : HWND;
                       Drive : Word;
                       fmtID : Word;
                       Options : Word) : Longint
   stdcall; external 'Shell32.dll' name 'SHFormatDrive';
   // on "récupère" ainsi la fonction SHFormatDrive contenu dans la DLL Shell32.dll sous le nom SHFormatDrive
 
procedure TForm1.Button1Click(Sender: TObject);
var OptionParDefaut:Word;
    drive:word;
    ResultatFormatage:integer;
begin
  if RadioButtonRapide.Checked then OptionParDefaut:=SHFMT_OPT_QUICKFORMAT else
    if RadioButtonComplet.Checked then OptionParDefaut:=SHFMT_OPT_FULLFORMAT else
      OptionParDefaut:= SHFMT_OPT_SYSONLY;
 
  if RadioButtonDriveA.Checked then drive:= SHFMT_DRV_A else
     drive:=SHFMT_DRV_B;
  Label2.Caption:='Formatage en cours';
  try
    ResultatFormatage:=ShFormatDrive(Handle, drive, SHFMT_ID_DEFAULT, OptionParDefaut);
    case ResultatFormatage of
      SHFMT_ERROR : Label2.Caption:='Erreur au formatage';
      SHFMT_CANCEL: Label2.Caption:='Arrêt par l''utilisateur';
      SHFMT_NOFORMAT:Label2.Caption:='?'
    else Label2.Caption:='Formatage terminé';
    end;
  except end;
end;
 
 
 
end. | 
Partager