硬碟格式化 |
答題得分者是:Vicen
|
sundy6719
初階會員 發表:136 回覆:78 積分:42 註冊:2002-07-10 發送簡訊給我 |
|
Vicen
高階會員 發表:13 回覆:145 積分:151 註冊:2005-03-14 發送簡訊給我 |
国外站点找到的,你可以参考一下。 // 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; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |