Formátování disků

Postup:
Založte nový formulář a nazvěte jej FDC.

Do tohoto formuláře přidejte komponent DriveListBox a tlačítko, které pojmenujte cmdFormat.

Do deklarací formuláře vložte následující kód:
Private Declare Function SHFormatDrive Lib "shell32" (ByVal hwnd As Long, ByVal Drive As Long, ByVal fmtID As Long, ByVal options As Long) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

* každá deklarace musí být celá na samostatné řádce

Na událost Click tlačítka cmdFormat vložte následující kód:

Private Sub cmdFormat_Click()

   Dim DriveLetter$, DriveNumber&, DriveType&
   Dim RetVal&, RetFromMsg%
   DriveLetter = UCase(Drive1.Drive)
   DriveNumber = (Asc(DriveLetter) - 65)
' Změna písmena na číslo disku: A=0
   DriveType = GetDriveType(DriveLetter)
   If DriveType = 2 Then
'Výměnný disk
      RetVal = SHFormatDrive(Me.hwnd, DriveNumber, 0&, 0&)
   Else
      RetFromMsg = MsgBox("Toto NENÍ výměnný disk !!!" & vbCrLf & "Formátovat ?", 276, "Format Example")
   Select Case RetFromMsg
      Case 6
         RetVal = SHFormatDrive(Me.hwnd, DriveNumber, 0&, 0&)
      Case 7
         ' Nic
      End Select
   End If

End Sub

Po spuštění této aplikace si vyberte disk a klepněte na tlačítko cmdFormat. Objeví se standardní dialog pro formátování disků.

Zpět

Autor: The Bozena