全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1442
推到 Plurk!
推到 Facebook!

硬碟格式化

答題得分者是:Vicen
sundy6719
初階會員


發表:136
回覆:78
積分:42
註冊:2002-07-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-11-05 01:33:26 IP:211.74.xxx.xxx 未訂閱
如何把硬碟在幕後給它格式化要使用什麼函數謝謝
Vicen
高階會員


發表:13
回覆:145
積分:151
註冊:2005-03-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-11-08 20:57:15 IP:221.226.xxx.xxx 未訂閱
国外站点找到的,你可以参考一下。    // formating a floppy drive, harddisk, or another drive
// Eine Diskette, Harddisk oder ein anderes Laufwerk formatieren    {
  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;//磁盘A
  SHFMT_DRV_B = 1;//磁盘B
  SHFMT_DRV_C = 2;//磁盘C ... 依此类推
  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;    //声明API函数
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
    //格式化A盘,改成SHFMT_DRV_C即格式化C盘了
    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.
}    //如果磁盘未准备就绪,调用SHFormatDrive时系统会提示错误,你可以在调用SHFormatDrive前用SetErrorMode设置系统错误模式为SEM_FAILCRITICALERRORS,这样系统就不会弹出报错了。    var
  EMode: Word;
begin
  EMode := SetErrorMode(SEM_FAILCRITICALERRORS);
  // ShFormatDrive Code....
  SetErrorMode(EMode);
end;
系統時間:2024-05-17 13:27:08
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!