格式"A"盘(100分)

  • 主题发起人 主题发起人 细文
  • 开始时间 开始时间

细文

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么样知道"A"盘有没有格式过及怎么样格式"A"盘?
 
一、98下可以:
{$I-}//必须加
procedure FormatA;
begin
chdir('A:');
if (ioresult=0) then exit;
showmessage('驱动器A中的无盘或没有格式化 !');
if (windows.messagebox(getactivewindow(),pchar(要格式化吗 ?),pchar('提示'),mb_yesno)=idno) then exit;
winexec('c:/windows/command/format.com','A:');
end;

二、或参考我回答的问题:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=781783

 
function SHFormatDrive(hWnd: HWND;
Drive: Word;
fmtID: Word;
Options: Word): Longint

stdcall; external 'Shell32.dll' name 'SHFormatDrive';
适用于所用windows操作系统
DWORD WINAPI SHFormatDrive(HWND hwnd,
UINT drive,
UINT fmtID,
UINT options);

//
// Special value of fmtID which means "use the defaultformat"
//

#define SHFMT_ID_DEFAULT 0xFFFF

//
// Option bits for options parameter
//

#define SHFMT_OPT_FULL 0x0001
#define SHFMT_OPT_SYSONLY 0x0002

//
// Special return values. PLEASE NOTE that these are DWORD values.
//

#define SHFMT_ERROR 0xFFFFFFFFL // Error on last format,
// drive may be formatable
#define SHFMT_CANCEL 0xFFFFFFFEL // Last format wascanceled
#define SHFMT_NOFORMAT 0xFFFFFFFDL // Drive is not formatable

#if defined (__cplusplus)
}
#endif
#endif
Here is an example call to SHFormatDrive that will format a diskette in drive "A:".
SHFormatDrive (hMainWnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
 
Delphi的例子:)给分吧,呵呵
Example:

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';

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
end;

end;

 
多人接受答案了。
 
后退
顶部