Link to home
Start Free TrialLog in
Avatar of k6__
k6__

asked on

How To Format A Floppy Disk Through Delphi 3

Any Ideas How To Format a floppy Disk without showing
any dialog ?
Avatar of ronit051397
ronit051397

There is an API hidden away in Shell32.dll called SHFormatDrive,
 this brings up the standard format removable drive dialog.

{implementation section}


const
        SHFMT_ID_DEFAULT      = $FFFF;  // Formating options
        SHFMT_OPT_QUICKFORMAT = $0000;
        SHFMT_OPT_FULL        = $0001;
        SHFMT_OPT_SYSONLY     = $0002;  // Error codes
        SHFMT_ERROR           = $FFFFFFFF;
        SHFMT_CANCEL          = $FFFFFFFE;
        SHFMT_NOFORMAT        = $FFFFFFFD;

function SHFormatDrive(Handle: HWND; Drive, ID, Options: Word): LongInt;
        stdcall; external 'shell32.dll' name 'SHFormatDrive'

procedure TForm1.btnFormatDiskClick(Sender: TObject);
var
  retCode: LongInt;

begin
 retCode:= SHFormatDrive(Handle, 0, SHFMT_ID_DEFAULT,SHFMT_OPT_QUICKFORMAT);
  if retCode < 0 then
      ShowMessage('Could not format drive');
end;

end.

You will need to contact the Dialog somehow, evt. via WinAPI, if you dont get it working or get another answer here, mail me and ill try code it for you..  brainware@software.dk


k6__

Why not use the DeviceIOControl API call and pass the parameter IOCTL_DISK_FORMAT_TRACKS etc. There are a lot more options as well like segtting the volume label etc...

The IOCTL_DISK_FORMAT_TRACKS DeviceIoControl operation formats a specified, contiguous set of tracks on a disk.

Later
BoRiS
Avatar of k6__

ASKER

i said i don't want to show any dialog.. so IOCTL_DISK_FORMAT_TRACKS function can do it ? an example ? =)

thanx =)

Avatar of k6__

ASKER



k6__

If you wanted code example all you had to do is ask(not reject the answer), for future
reference ask for source code examples in the first question...

Anyway enough of that now (GEEZ)

I'll give you an example, let me just check it out again...

Later
BoRIS
Avatar of k6__

ASKER

ermmh =| sorry ... i accidentally rejected it... =(
i thouht that i choose Acceptable .. =(
sorry again Boris

Why not use the CreateProcess or WinExec to use the format program under c:\dos.
And by giving the SW_HIDE as a parameter to hide the window, and a text file to redirect to FORMAT program to respond to the prompts from the FORMAT command(like insert diskette, enter volume label...)


Avatar of k6__

ASKER

Nope ... i though of that but i don't want to call DOS through
my app =)

Thanx...

ASKER CERTIFIED SOLUTION
Avatar of jeurk
jeurk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Drop a component to the form, and call yourcomponent.execute
you will have no dialog opening.
I hope it helps.
Jeurk
Avatar of k6__

ASKER

jeurk thanx but i didn't want that.. i knew the SHFormatDrive
function of Shell32.dll but anyway somebody posted the answer
that i was looking through a win32s Function =)


Hello,
So why did I earned the points ;) ?

Avatar of k6__

ASKER

your ean points cause i accidentally REJECTED =( the right
answer =(