| :: How to show the standard dialog box that prompts to Format a Floppy Drive... |
Author |
Andrea Tincani |
Language |
VB5, VB6 |
Operating
Systems |
Windows 95, 98 and NT |
| API
Declarations |
Option Explicit
'API calls
Private Declare Function SHFormatDrive Lib "shell32.dll" (ByVal hwnd As Long, ByVal Drive As
Long, ByVal fmtID As Long, ByVal options As Long) As Long
Private Declare Function GetDriveType Lib "kernel32.dll" Alias "GetDriveTypeA"
(ByVal nDrive As String) As Long
'Drive type constants
Public Const DRIVE_CDROM = 5
Public Const DRIVE_FIXED = 3
Public Const DRIVE_RAMDISK = 6
Public Const DRIVE_REMOTE = 4
Public Const DRIVE_REMOVABLE = 2
Public Const SHFMT_ID_DEFAULT = &HFFFF ' Option bits for options parameter
Public Const SHFMT_OPT_FULL = 1
Public Const SHFMT_OPT_SYSONLY = 2 |
| Module
|
Public Sub FormatFloppy(hWndOwner As Long, ByVal DriveLetter As
String)
Dim DriveNum As Long
Dim DriveType As Long
Dim ret As Long
' Add the
root path to the drive letter
DriveLetter = Left(DriveLetter, 1) & ":\"
' Convert
the drive letter into the corresponding drive number, A=0, B=1...
DriveNum = Asc(UCase(DriveLetter)) - Asc("A")
DriveType = GetDriveType(DriveLetter)
' Check if
the drive is a floppy drive
If DriveType = DRIVE_REMOVABLE Then
ret = SHFormatDrive(hWndOwner, DriveNum,
SHFMT_ID_DEFAULT, SHFMT_OPT_FULL)
Else
MsgBox "This is not a floppy drive!",
vbExclamation, "Format Floppy Disk"
End If
End Sub |
| Usage
|
'Usage:
Private Sub Command1_Click()
FormatFloppy Me.hwnd, "A"
End Sub |
|
 |
|
 |