Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to format a disk Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Format a disk 30-Aug-02
Category
Files Operation
Language
Delphi 2.x
Views
103
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas 

How to format a disk

Answer:

Use the SHFormatDrive- function in then Shell32.dll. You will get (Windows NT, 
Win95 ???) the standard format-disk- dialog. Put the following in your 
interface-part:

1   const
2     SHFMT_ID_DEFAULT = $FFFF; {Default for physical format}
3     SHFMT_OPT_QUICKFORMAT = $0000; {do quick formatting}
4     SHFMT_OPT_FULL = $0001; {complete formatting}
5     SHFMT_OPT_SYSONLY = $0002; {copy system files only}
6     SHFMT_ERROR = $FFFFFFFF; {formatting error}
7     SHFMT_CANCEL = $FFFFFFFE; {formatting aborted}
8     SHFMT_NOFORMAT = $FFFFFFFD; {unable to format}
9   
10  function SHFormatDrive(hWnd: HWND; Drive, fmtID, Options: Word): Longint; stdcall;
11  
12  implementation
13  
14  const
15    Shell32 = 'Shell32.dll';
16  
17  function SHFormatDrive; external Shell32 name 'SHFormatDrive';
18  
19  //And a little example for executing the function and formatting drive A:
20  
21  procedure TMainFrm.DiskFormatClick(Sender: TObject);
22  var
23    FmtRes: longint;
24    DriveNo: word;
25  begin
26    DriveNo := 0; {Drive A}
27    try
28      FmtRes := ShFormatDrive(Handle, DriveNo, SHFMT_ID_DEFAULT, 
29  SHFMT_OPT_QUICKFORMAT);
30      if FmtRes < 0 then
31        ShowMessage('Error or Abort Formatting');
32    except
33    end;
34  end;



Solve 2:

35  procedure FormatFloppy(Drive: byte);
36  {Procedure to bring up the standard Windows format dialog to format a floppy drive.
37  Pass 0 for A:\ or 1 for B:\ }
38  type
39    TSHFormatDrive = function(hWnd: HWND; Drive: Word; fmtID: Word;
40      Options: Word): Longint stdcall;
41  var
42    SHFormatDrive: TSHFormatDrive;
43    LibHandle: THandle;
44  begin
45    LibHandle := LoadLibrary(PChar('Shell32.dll'));
46    if LibHandle <> 0 then
47      @SHFormatDrive := GetProcAddress(LibHandle, 'SHFormatDrive')
48    else
49    begin
50      MessageDlg('Failed to load Shell32.dll.', mtError, [mbOK], 0);
51      Exit;
52    end;
53    if @SHFormatDrive <> nil then
54      SHFormatDrive(Application.Handle, Drive, { 0 = A:\, 1 = B:\ } $FFFF, 0);
55    FreeLibrary(LibHandle);
56    @SHFormatDrive := nil;
57  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC