关于超想
本站导航
邮件列表
  首页 | 本站产品 | Delphi资料 | 免费资源 | 程序人生 | 软件工程 | 网站设计 | 推荐网站
你所在的位置 -> 主页 -> 超想软件 -> 编程资料 -> Vb -> API文章 ->详细
相关内容  
 
 
在Delphi程序中应用IE浏览器控件
 
【新品推荐】

  详细内容
 

磁盘格式化
作者: 评价: 上站日期: 2001-09-01
内容说明:
来源:


   在Windows 9X中,当用鼠标右键单击“我的电脑”中的“3.5软盘A”然后在出现的右键菜单中选择“格式化”选项,就将弹出标准的“磁盘格式化”窗口。下面我们来看看如何在应用程序中利用函数轻松调用Windows 95标准的“磁盘格式化”窗口,实现对磁盘相应的操作功能。
程序的编写
1.与上例相同,首先运行VB,新建一个标准工程,然后利用“工具箱”在Form1窗体中加入一个命令按钮对象,将该命令按钮属性中的Caption值定义为“软盘格式化”。完成之后双击该按钮,在代码输入框中输入以下代码:
Private Sub Command1_Click()
Call FormatFloppy '调用FormatFloppy过程
End Sub
2.然后用鼠标右击窗体,选择右键菜单中的“添加/添加模块”选项,然后在出现的选择框中选择“模块”类型,接着在出现的模块代码输入框中加入以下代码:(注:模块是指一组声明的集合,其后为过程)
'通用声明
Public Const WM_CLOSE=&H10
Declare Function FindWindow Lib "user32" Alias"FindWindowA"(ByVal lpClassName As Any, ByVal
lpWindowName As Any)As Long
Delare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer
As String, ByVal nSize As Long) As Long
Declare Function SetWindowPos Lib "user32"(BvVal 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
Declare Function GetWindowRect Lib "user32"(ByVay hwnd As Long, lpRect As RECT) As Long
Declare Sub Sleep Lib "kernel32" (ByValdwMilliseconds As Long)
Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
TypePOINTAPI
    X As Long
    y As Long
End Type
Const SWP_NOSIZE=&H1
Const SWP_NOZORDER=&H4
'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
程序的执行
程序输入完成后,点击VB“运行”菜单中的“启动”或“全面编译”命令,点击“软盘格式化”按钮后选择要格式化的容量,即可对3.5英寸盘进行格式化操作。

 
你所在的位置 -> 主页 -> 超想软件 -> 编程资料 -> Vb -> API文章 ->详细
  首页 | 本站产品 | Delphi资料 | 免费资源 | 程序人生 | 软件工程 | 网站设计 | 推荐网站
声明:本站内容除注明原创以外均从网上摘抄,如有侵权请指明。
  如果您对我们的网站有什么意见或者建议,请与我们联系
powered by 建站易上手- V2.0