borderAndreaVB free resources for Visual Basic developersborder

AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincani
:: 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

:: Navigation

Home

Files and Disks Tips

Previous Tip

Next Tip

:: Search this site
Google
:: Related Topics
icon 28-02-2008 Re: How to create a common menu for whole proj? #1 by Bharathi
icon 29-10-2004 Re: Different printers in access by GeoffS
icon 18-09-2004 getting there by sai
icon 16-09-2004 Re: Coverting an MS access database by yronium
icon 15-09-2004 Re: Crystal Report & VB by amitsaxena
:: Sponsored Links



Partners: Il portale per lui e lei | Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder