dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic
Expertise: Advanced
Aug 5, 1997

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Format or Copy Diskettes Using Windows API

The Win32 API includes a pair of functions that let you format and copy diskettes from your programs:
 
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
Add two command buttons to your form, named cmdDiskCopy and cmdFormatDrive, and place this code into their Click events:
 
Private Sub cmdDiskCopy_Click()
        ' DiskCopyRunDll takes two 
        ' parameters- From and To
        Dim DriveLetter$, DriveNumber&, _
                DriveType&
        Dim RetVal&, RetFromMsg&
        DriveLetter = UCase(Drive1.Drive)
        DriveNumber = (Asc(DriveLetter) - _
                65)
        DriveType = GetDriveType_
                (DriveLetter)
        If DriveType = 2 Then  'Floppies, _
                etc
                RetVal = Shell_
                        ("rundll32.exe " & _
                        "diskcopy.dll," _
                        & "DiskCopyRunDll " & _
                        DriveNumber & "," & _
                        DriveNumber, 1) 
        Else   ' Just in case
                RetFromMsg = MsgBox_
                        ("Only floppies can be " & _
                        "copied", 64, _
                        "DiskCopy Example")
        End If
End Sub

Private Sub cmdFormatDrive_Click()
        Dim DriveLetter$, DriveNumber&, _
                DriveType&
        Dim RetVal&, RetFromMsg%
                DriveLetter = UCase(Drive1.Drive)
        DriveNumber = (Asc(DriveLetter) - _
                65) 
        ' Change letter to Number: A=0
        DriveType = GetDriveType_
                (DriveLetter)
        If DriveType = 2 Then  _
                'Floppies, etc
                RetVal = SHFormatDrive(Me.hwnd, _
                        DriveNumber, 0&, 0&)
        Else
                RetFromMsg = MsgBox_
                        ("This drive is NOT a " & _
                        "removeable drive! " & _
                        "Format this drive?", _
                        276, "SHFormatDrive Example")
                If RetFromMsg = 6 Then
                        ' UnComment to do it...
                        'RetVal = SHFormatDrive_
                                (Me.hwnd, _
                                '   DriveNumber, 0&, 0&)
                End If
        End If
End Sub
Add one DriveListBox control named Drive1:
 
Private Sub Drive1_Change()
        Dim DriveLetter$, DriveNumber&, _
                DriveType&
        DriveLetter = UCase(Drive1.Drive)
        DriveNumber = (Asc(DriveLetter) - _
                65)
        DriveType = GetDriveType_
                (DriveLetter)
        If DriveType <> 2 Then  _
                'Floppies, etc
                cmdDiskCopy.Enabled = False
        Else
                cmdDiskCopy.Enabled = True
        End If
End Sub
Be careful: this function can even format the hard disk.
Duncan Diep
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date