|
|
|
|
|
Dicas
|
|
Visual Basic (Arquivos/Diretórios)
|
|
|
Título da Dica: Formatando um Disquete
|
|
|
|
Postada em 15/8/2003 por d@®l@n
Este exemplo chama a caixa de diálogo Formatar Disquete do Windows Explorer. Coloque um botão num Form e coloque o seguinte código: 'Num módulo: Option Explicit
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
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 Public Const SHFMT_OPT_FULL = 1 Public Const SHFMT_OPT_SYSONLY = 2
Public Sub FormatFloppy(hWndOwner As _ Long, ByVal DriveLetter As String) Dim DriveNum As Long, DriveType As Long Dim ret As Long DriveLetter = Left(DriveLetter, 1) & ":\" DriveNum = Asc(UCase(DriveLetter)) - Asc("A") DriveType = GetDriveType(DriveLetter) If DriveType = DRIVE_REMOVABLE Then ret = SHFormatDrive(hWndOwner, _ DriveNum, SHFMT_ID_DEFAULT, _ SHFMT_OPT_FULL) Else MsgBox "O drive informado não é um " & _ "drive de discos removíveis", _ vbExclamation, "Formatar Disquete" End If End Sub
'No evento click do botao:
Private Sub Command1_Click() FormatFloppy Me.hwnd, "A" 'Neste caso, estaria mandando formatar o drive A:. End Sub
|
|
|
|
|