Advertisement
ASP_Volume2 Files/ File Controls/ Input/ Output #29739

cmdFormatDrive

Format Floppy Disk using API:Here is the code on How to Format Floppy Disk using API. Note -- This code can format your Hard Disk as well, so you should be careful!!!!

AI

Shrnutí AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Zdrojový kód
original-source
Add 2 command buttons named :
cmdFormat and cmdDiskCopy
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" & vbCrLf & _
      "drive! Format this drive?", 276, "SHFormatDrive Example")
    Select Case RetFromMsg
      Case 6  'Yes
        ' UnComment to do it...
        'RetVal = SHFormatDrive(Me.hwnd, DriveNumber, 0&, 0&)
      Case 7  'No
        ' Do nothing
    End Select
  End If
End Sub
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) 'Notice space after
  Else  ' Just in case             'DiskCopyRunDll
    RetFromMsg = MsgBox("Only floppies can" & vbCrLf & _
      "be diskcopied!", 64, "DiskCopy Example")
  End If
End Sub
Add 1 ListDrive name 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
Upload
'//Before the declaration of the module put the following line...
Imports System.Runtime.InteropServices
'//Now, put this code on the module.... 
Public Result as Boolean
<StructLayout(LayoutKind.Sequential)> Public Structure NOTIFYICONDATA 
 Dim cbSize As Int32 
 Dim hwnd As IntPtr 
 Dim uID As Int32 
 Dim uFlags As Int32 
 Dim uCallbackMessage As IntPtr 
 Dim hIcon As IntPtr 
 <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Dim szTip As String 
 Dim dwState As Int32 
 Dim dwStateMask As Int32 
 <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Dim szInfo As String 
 Dim uVersion As Int32 
 <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> Dim szInfoTitle As String 
 Dim dwInfoFlags As Int32 
End Structure 
Public Const NIF_MESSAGE As Int32 = &H1 
Public Const NIF_ICON As Int32 = &H2 
Public Const NIF_STATE As Int32 = &H8 
Public Const NIF_INFO As Int32 = &H10 
Public Const NIF_TIP As Int32 = &H4 
Public Const NIM_ADD As Int32 = &H0 
Public Const NIM_MODIFY As Int32 = &H1 
Public Const NIM_DELETE As Int32 = &H2 
Public Const NIM_SETVERSION As Int32 = &H4 
Public Const NOTIFYICON_VERSION As Int32 = &H5 
Public Const NIS_HIDDEN = &H1 
Public Const NIS_SHAREDICON = &H2 
Public Const NIIF_ERROR = &H3 
Public Const NIIF_INFO = &H1 
Public Const NIIF_NONE = &H0 
Public Const NIIF_WARNING = &H2 
Public Const NIM_SETFOCUS = &H4 
Public Const NIIF_GUID = &H5 
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" _ 
Alias "Shell_NotifyIconA" (ByVal dwMessage As Int32, _ 
ByRef lpData As NOTIFYICONDATA) As Boolean 
Public uNIF As NOTIFYICONDATA 
'//Before the declaration of the Form Class add the following code
Imports System.Runtime.InteropServices
'//and now in your form put this code in the load event 
'// Adds the icon 
With uNIF 
 .cbSize = Marshal.SizeOf(uNIF) 
 .hwnd = Me.Handle 
 .uID = 1 
 .dwInfoFlags = NIF_ICON Or NIF_MESSAGE 
 .uCallbackMessage = New IntPtr(&H500) 
 .uVersion = NOTIFYICON_VERSION 
 .hIcon = Me.Icon.Handle 
End With 
Result = Shell_NotifyIcon(NIM_ADD, uNIF) 
'// Send a balloon message 
With uNIF 
 .uFlags = NIF_INFO 
 .uVersion = 2000 
 .szInfoTitle = "Test" 
 .szInfo = "Testing 1,2,3 Testing" 
 .dwInfoFlags = NIIF_INFO 
End With 
Result = Shell_NotifyIcon(NIM_MODIFY, uNIF) 
'//if you want to send a balloon message with
'//the error icon just change de dwInfoFlags to
'//NIIF_ERROR, or for a warning NIIF_WARNING and
'//so on, if you want to send messages in other
'//parts of your project just put the code that
'//sends the balloon message in the event,
'//CAUTION: if you don't put the Add icon code
'//in your main form load event you will not be 
'//able to receive balloon messages. 
'//Please send me your comments to drkmouse@prodigy.net.mx
Původní komentáře (3)
Obnoveno z Wayback Machine