放到模块中调用FormatFloppyType RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Type POINTAPI
x As Long
y As Long
End Type
Const SWP_NOSIZE = &H1
Const SWP_NOZORDER = &H4
Public Const WM_CLOSE = &H10
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Declare Sub Sleep Lib "kernel32" (ByValdwMilliseconds As Long)
'FormatFloppy()¹ý³ÌÉùÃ÷
Public Sub FormatFloppy()
Dim sBuffer As String, Windir As String, Procs As String, x
Dim lResult As Long
sBuffer = String$(255, 0)
lResult = GetWindowsDirectory(sBuffer, Len(sBuffer))
Windir = Trim(sBuffer)
Procs = Left(Windir, lResult) & "\rundll32.exe shell32.dll,SHFormatDrive"
Call CenterDialog("Format - 3? Floppy (A:)")
x = Shell(Procs, 1)
Call CenterDialog("Format - 3? Floppy (A:)")
k = LockWindowUpdate(0)
End Sub
' CenterDialog ¹ý³ÌÉùÃ÷
Public Sub CenterDialog(WinText As String)
DoEvents
On Error Resume Next
Dim D3 As Long
D3 = LockWindowUpdate(GetDesktopWindow())
Dim wdth%
Dim hght%
Dim Scrwdth%
Dim Scrhght%
Dim lpDlgRect As RECT
Dim lpdskrect As RECT
Dim hTaskBar As Long
hTaskBar = FindWindow(0&, WinText)
Call GetWindowRect(hTaskBar, lpDlgRect)
wdth% = lpDlgRect.Right - lpDlgRect.Left
hght% = lpDlgRect.Bottom - lpDlgRect.Top
Call GetWindowRect(GetDesktopWindow(), lpdskrect)
Scrwdth% = lpdskrect.Right - lpdskrect.Left
Scrhght% = lpdskrect.Bottom - lpdskrect.Top
x% = (Scrwdth% - wdth%) / 2
y% = (Scrhght% - hght%) / 2
Call SetWindowPos(hTaskBar, 0, x%, y%, 0, 0, SWP_NOZORDER Or SWP_NOSIZE)
DoEvents
End Sub
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Type POINTAPI
x As Long
y As Long
End Type
Const SWP_NOSIZE = &H1
Const SWP_NOZORDER = &H4
Public Const WM_CLOSE = &H10
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Declare Sub Sleep Lib "kernel32" (ByValdwMilliseconds As Long)
'FormatFloppy()¹ý³ÌÉùÃ÷
Public Sub FormatFloppy()
Dim sBuffer As String, Windir As String, Procs As String, x
Dim lResult As Long
sBuffer = String$(255, 0)
lResult = GetWindowsDirectory(sBuffer, Len(sBuffer))
Windir = Trim(sBuffer)
Procs = Left(Windir, lResult) & "\rundll32.exe shell32.dll,SHFormatDrive"
Call CenterDialog("Format - 3? Floppy (A:)")
x = Shell(Procs, 1)
Call CenterDialog("Format - 3? Floppy (A:)")
k = LockWindowUpdate(0)
End Sub
' CenterDialog ¹ý³ÌÉùÃ÷
Public Sub CenterDialog(WinText As String)
DoEvents
On Error Resume Next
Dim D3 As Long
D3 = LockWindowUpdate(GetDesktopWindow())
Dim wdth%
Dim hght%
Dim Scrwdth%
Dim Scrhght%
Dim lpDlgRect As RECT
Dim lpdskrect As RECT
Dim hTaskBar As Long
hTaskBar = FindWindow(0&, WinText)
Call GetWindowRect(hTaskBar, lpDlgRect)
wdth% = lpDlgRect.Right - lpDlgRect.Left
hght% = lpDlgRect.Bottom - lpDlgRect.Top
Call GetWindowRect(GetDesktopWindow(), lpdskrect)
Scrwdth% = lpdskrect.Right - lpdskrect.Left
Scrhght% = lpdskrect.Bottom - lpdskrect.Top
x% = (Scrwdth% - wdth%) / 2
y% = (Scrhght% - hght%) / 2
Call SetWindowPos(hTaskBar, 0, x%, y%, 0, 0, SWP_NOZORDER Or SWP_NOSIZE)
DoEvents
End Sub
解决方案 »
- 看语句“INSERT INTO x SELECT * From y”,如果y表中有一个和x表相同的记录,就报错,使得程序无法执行下去。如何使得重复的记录不插入
- 请教:vb可不可以实现动态创建一个类,动态定义其方法和属性
- winsock连续getdata的问题
- 我有一个关于打印的问题,请各位帮忙解决,谢谢各位高手的支持。
- 新人提问,TreeView控间怎么默认展开?
- OfficeXP样式的菜单比较好看,不知该如何做(直接用GDI吗)?
- 如何保存CSDN上的网页?
- 请教比较中文字符串大小(上海比北京小)的问题。
- 谁知道ERD,UML是什么意思?
- VB DLL工程求转成VC DLL工程
- <<< RichTextBox 如何实现平滑上下滚动?>>>>
- Data.Recordset的一个小问题,多谢!(超级菜的)
'API
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
Private Declare Function GetActiveWindow Lib "user32" () As Long
'Constants
Private Const DRIVE_CDROM = 5, DRIVE_FIXED = 3
Private Const DRIVE_RAMDISK = 6, DRIVE_REMOTE = 4
Private Const DRIVE_REMOVABLE = 2, SHFMT_ID_DEFAULT = &HFFFF
Private Const SHFMT_OPT_FULL = 1, SHFMT_OPT_SYSONLY = 2
'Purpose : Format a Floppy Disk
'Inputs : [sDriveLetter] The drive letter (usually "A")
'Outputs : Returns -1 if the drive specified isn't a floppy drive
' Returns -2 if the user pressed cancel
' Returns 6 if the format succeeded
'Author : Andrew Baker
'Date : 09/12/2000 03:05
'Notes :
'Revisions :
Public Function FormatFloppy(Optional ByVal sDriveLetter As String = "A") As Long
Dim lDriveNum As Long
Dim lDriveType As Long, lhWndOwner As Long
On Error GoTo ErrFailed
'Add the root path to the drive letter
sDriveLetter = Left$(sDriveLetter, 1) & ":\"
lhWndOwner = GetActiveWindow
'Convert the drive letter into the corresponding drive number
lDriveNum = Asc(UCase$(sDriveLetter)) - Asc("A")
lDriveType = GetDriveType(sDriveLetter)
If lDriveType = DRIVE_REMOVABLE Then
'Drive is a floppy drive
FormatFloppy = SHFormatDrive(lhWndOwner, lDriveNum, SHFMT_ID_DEFAULT, SHFMT_OPT_FULL)
Else
'Drive is not a Floppy disk drive
FormatFloppy = -1
End If
Exit Function
ErrFailed:
'Error Handler
FormatFloppy = Err.LastDllError
On Error GoTo 0
End Function
'Demonstration routine
Sub Test()
Dim lRet As Long
lRet = FormatFloppy("A")
If lRet = -1 Then
'Failed
MsgBox "Drive A is Not a Floppy"
ElseIf lRet = 6 Then
'Succeed
MsgBox "Formated Drive A"
Else
MsgBox "Failed"
End If
End Sub