您的批评和鼓励都是我把编程无限办好的动力! 您编程时遇到困难,或遇到不顺心的事想发发牢骚尽管到这里来吧! 虽然本网力求全面,但也不能包罗万象,这些我筛选出的优秀网站连接就是对本站最好的补充! 学习编程当然也离不开书本了,这里收集大量编程书籍! 编程无限之源码超市,这里收集的代码令你意想不到的全面! 欢迎光临编程网校,这里专门收集VB/CB入门文章及技术文章! 欢迎光临编程无限!
     
       
 
当前位置:英文资料 >> FileSystem
Format a floppy disk
  资料类型: FileSystem 上传时间: 2001-02-21 阅读次数: 2349



There is no easy way to format a floppy disk in Windows 3.1. The following solution is not elegant, but it seems the only way to go unless you use a specially written DLL . Microsoft should have given developers access to this kind of function through the File Manager. Oh, well...

The best way to format a disk is to use DOS (our old friend). Here are some tips.

Make sure that the disk is a floppy (removable) disk!
To make things faster, use the Quick Format option available from DOS 5.0 and above.
Declare The Following

Declare Function WinExec Lib "Kernel" (ByVal lpCmdLine _

As String, ByVal nCmdShow As Integer) As Integer

Declare Function GetNumTasks Lib "Kernel" () As Integer

Declare Function GetDriveType Lib "Kernel" (ByVal nDrive As Integer) As Integer

Declare Function GetTempFileName Lib "Kernel" _

(ByVal cDriveLetter As Integer, ByVal lpPrefixString _

As String, ByVal wUnique As Integer, ByVal _

lptempfilename As String) As Integer

Declare Function GetVersion Lib "Kernel" () As Long

Use the following Function

Function iFormatFloppyDisk (sDriveLetter As String, _

sVolumeName As String) As Integer

Dim sCommand As String

Dim sTempFile As String

Dim iFileNum As Integer

Dim iReturn As Integer

Dim iActiveApps As Integer

Dim sQuickFormat As String

Dim X As Integer

Const SW_HIDE = 0



'MakeSure that the drive if removable

If GetDriveType(Asc(Left(sDriveLetter, 1)) - 65) _

<> 2 Then

FormatFloppyDisk = False

Exit Function

End If



'Format Driveletter

sDriveLetter = Left$(sDriveLetter, 1) & ":"



'If 5.0 or Higher Use Quick Format

If Val(sGetDosVer()) >= 5 Then

sQuickFormat = "/Q"

Else

sQuickFormat = ""

End If



'Get Temp File Name

sTempFile = sGetTempFile("FFD")



'Create Input File (for hands-off operation)

sCommand = Chr(13) & Chr(10) & Chr(13) & Chr(10) & "N" _

& Chr(13) & Chr(10)

iFileNum = FreeFile

Open sTempFile For Output As #iFileNum

Print #iFileNum, sCommand

Close #iFileNum



'Format Disk

iActiveApps = GetNumTasks()

iReturn = WinExec("doswin.pif /c c:dosformat " & _

sDriveLetter & " /v:" & sVolumeName & sQuickFormat _

& "/u <" & sTempFile, SW_HIDE)

Do While GetNumTasks() <> iActiveApps

X = DoEvents()

Loop



'Get Rid Of The Temp File

Kill sTempFile



'Return WinExec Value (any value above 32

‘means success!)

iFormatFloppyDisk = iReturn

End Function



Function sGetTempFile (sPrefix As String) As String

Dim sTempFileName As String

Dim R As Integer



sTempFileName = Space$(144)



R = GetTempFileName(ByVal 0, ByVal sPrefix, _

ByVal 0, ByVal sTempFileName)



sGetTempFile = Mid$(sTempFileName, 1, _

Len(Trim$(sTempFileName)) - 1)

End Function



Function sGetDosVer () As String

Dim lVer As Long

Dim lDosVer As Long



lVer = GetVersion()

lDosVer = CInt(lVer / &H10000)

sGetDosVer = Format$(lDosVer / 256) + "." _

+ Format$(lDosVer And &HFF)

End Function

If this Function returns a value greater than 32, then everything went well. If you don’t want your users to see the DOS screen while the formatting takes place, create a PIF file called DOSWIN.PIF and set Display Usage set to Windowed.


推荐给朋友 点 评( 0 ) 返回前页 关闭此页
   
  本类最热文章排名:
  1.Copy File
2.how to send files to the Recycle Bin
3.detect a DBF file is being used
4.a function to verify if a file exists
5.Move a File
6.This function return...
7.Create an entire dir...
8.Lauches an applicati...
9.complete control ove...
10.go over the major fu...
   
   
  评论:
 
 
 

 

关于本站 版权声明 联系方法
编程无限 V4.1 Copyright © 1999-2008 21code.com

京ICP备05006938号