VB 版 (精华区)

发信人: alias (白桦林), 信区: VB
标  题: Win95系统API函数大揭秘(3)
发信站: 哈工大紫丁香 (Wed Jul 26 10:54:34 2000), 转信

发信人: yucheng (Bingo), 信区: VisualBasic       
发信站: BBS 水木清华站 (Fri Feb 25 17:23:37 2000)

磁盘格式化
当鼠标右键单击“3.5软盘A”并选择“格式化”时,则弹出标准的“磁盘格式化”
窗口。我们
也可以在应用程序中利用函数轻松调用Windows 95标准的“磁盘格式化”窗口,以实
现对磁盘相应
的操作功能。
窗体加入如下代码:
Private Sub Form_Click()
FormatFloppy
End Sub
加入代码如下的模块:
Public Const WM_CLOSE = &H10
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassN
ame As Any, ByVal
lpWindowName As Any) As Long
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirecto
ryA" (ByVal
lpBuffer As String, ByVal nSize As Long) As Long
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndIn
sertAfter 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 L
ong
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As R
ECT) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Type 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 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
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


--
有人说我捂着脸的时候特象周润发,你信不信?
    Flying                            Fox          
   Flying                       Fox                 
     Flying                  Fox              
        Flying            Fox                   
           Flying      Fox                      

--
☆ 来源:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: mig.bbs@smth.org]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:4.964毫秒