好像调用SHELL不好控制,如倒底格式化的结果怎么样及出错等

解决方案 »

  1.   

    有专门的API,你可以查一查!
      

  2.   

    我在MSDN中翻了半天也没有找到头绪,到底是哪一个嘛?
      

  3.   

    在http://www.nccsoft.com/delphi/中分类统计下的“档案元件”的第2页中有一个TFormat v1.0 作者: Mike Johnson (1998/03/26)
    TFormat 是能夠格式化磁碟機的元件.
    Format floppy disks in Win32 enviroment. Used undocumented API functions of shell32.dll. (2 kb) 请看看是否可用。
      

  4.   

    哈哈,看我的答案!      function SHFormatDrive(hWnd : HWND;Drive, fmtID, Options : WORD) : longint; stdcall; external  'shell32.dll';
          function _DiskFormat( const Drive : Char ):string; //对一个可移动驱动器或硬盘驱动器格式化,注意这个函数是非常危险的.
          var
            wDrive       : WORD;
            dtDrive      : string;
            formatretcode:longint;
            begin
              dtDrive := _DiskDriverType(Upcase(Drive));
              if not _OK(dtDrive) then begin
                result:=dtDrive+'(DiskFormat)'; exit;
              end;
              // if it's not a HDD or a FDD then raise an exception
              if (not _Contain('可移动',dtDrive)) and (not _Contain('硬盘',dtDrive)) then
                result := badresult+'无法格式化一个'+dtDrive
              else begin// 进行格式化
                wDrive := Ord( UpCase(Drive) ) - Ord( 'A' );
                // SHFormatDrive 是一个没有公开的 API 函数调用
                formatretcode:=SHFormatDrive( Application.Handle, wDrive, $ffff, 0);
                if formatretcode=-1 then  result:=badresult+'格式化程序已执行,在格式化中发生错误,返回代码:'+inttostr(formatretcode)
                else if formatretcode=-2 then  result:=badresult+'格式化程序已执行,用户放弃格式化驱动器:'+Drive
                else if formatretcode=6 then  result:='格式化程序已执行,完成驱动器:'+Drive+'的格式化'
                     else result:='格式化程序已执行,返回代码:'+inttostr(formatretcode);
              end; // else
            end;