| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2264 人关注过本帖
标题:vb 进度条问题请教?
只看楼主 加入收藏
shuyoufeng
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-7-3
收藏
 问题点数:0 回复次数:5 
vb 进度条问题请教?
用VB写了个运行外部程序的工具,想在运行外部程序时,在FORM窗体上显示该程序的进度条,
现在是外部程序是可以运行了,可是运行时窗体上什么动作都没有,现在的想法是,能不能在窗体上做一个进度条来显示程序的运行进程,请高手花点时间帮帮忙,在此谢谢了!

我的代码如下:

Option Explicit
  Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
  Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

  Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
  Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
  Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
  Private Declare Function GetForegroundWindow Lib "user32" () As Long
  Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
  
  Const PROCESS_QUERY_INFORMATION = &H400
  Const STILL_ALIVE = &H103
  Const INFIN99vE = &HFFFF
  
  Private ExitCode As Long
  Private hProcess As Long
  Private isDone As Long

  Private Sub Form_Load()
  
  Dim DrvNum As Single
  Dim DrvName As String
  
  Dim DrvSys As String
  Dim DrvSet As String
  
  Dim DrvType As Integer
  
  Dim i As Integer
  
  Dim StrBuff As String
  Dim rtn As Long
  
   
  Me.AutoRedraw = True
  Drvbox.Visible = False
  
  StrBuff = Space(255)
   
  rtn = GetWindowsDirectory(StrBuff, 255)
   
  drvlisttitle.AddItem "盘符                                       " + "磁盘类型" + "                               是否系统盘"
  DrvNum = Asc("a") - 1
  For i = 0 To Drvbox.ListCount
  DrvNum = DrvNum + 1
  DrvName = Chr(DrvNum) + ":\"
  DrvType = GetDriveType(DrvName)
  
  DrvSet = Left(StrBuff, 1)
  DrvSys = Left(DrvName, 1)
  
  Select Case GetDriveType(DrvName)
  Case 3
  If DrvSet = UCase(DrvSys) Then drvlist.AddItem Trim(UCase(Chr(DrvNum))) + "                         本地硬盘" + "                      是" Else drvlist.AddItem Trim(UCase(Chr(DrvNum))) + "                         本地硬盘" + "                      否"
  End Select
  Next i
   
  SELTYPE1.Value = False
  SELTYPE2.Value = False
  
  SELTYPE1.Caption = "FAT32"
  SELTYPE2.Caption = "NTFS"
  
  enter.Enabled = False

  End Sub

Private Sub SELTYPE1_Click()
If SELTYPE1.Value = True And drvlist.Text <> "" Then enter.Enabled = True
End Sub

Private Sub SELTYPE2_Click()
If SELTYPE2.Value = True And drvlist.Text <> "" Then enter.Enabled = True
End Sub

Private Sub drvlist_Click()
If drvlist.Text <> "" And SELTYPE1.Value = True Or SELTYPE2.Value = True Then enter.Enabled = True
End Sub

Private Sub enter_Click()
Dim ParPath As String, SelTypeV As String
ParPath = Left(drvlist.Text, 1) + ":"

If SELTYPE1.Value = True Then SelTypeV = "FAT32" Else If SELTYPE2.Value = True Then SelTypeV = "NTFS" Else MsgBox "请选择格式类型!"

Dim str2 As Integer
str2 = MsgBox("安装程序将要对你选择的分区格式,你确认要格式化吗?", vbOKCancel, "格式化确认")

If str2 = vbOK Then
settext.Visible = False
drvlisttitle.Visible = False
drvlist.Visible = False
fortype.Visible = False
SELTYPE1.Visible = False
SELTYPE2.Visible = False
enter.Enabled = False
title.FontSize = 12
title.Top = 800
title.Caption = "正在格式化你选择的分区,请稍候...."

Dim ForPro As Long, BTSect As Long, CopySys As Long, lngPHandle As Long, PathCD As String, i As Integer, DrvNum As Single, DrvName As String

DrvNum = Asc("a") - 1
For i = 0 To Drvbox.ListCount
  DrvNum = DrvNum + 1
  DrvName = Chr(DrvNum) + ":\"
  
  Select Case GetDriveType(DrvName)
  Case 5
  PathCD = Trim(UCase(Chr(DrvNum))) + ":\SOURCES"
  End Select
  Next i

ForPro = Shell(PathCD + "\ " + ParPath + " /fs:" + SelTypeV + " /q /y", vbHide)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, ForPro)
isDone = False
Do
cancel.Enabled = False
Call GetExitCodeProcess(hProcess, ExitCode)
Debug.Print ExitCode
DoEvents
Loop While ExitCode = STILL_ALIVE
Call CloseHandle(hProcess)
isDone = True

title.Caption = "正在设置分区,请稍候...."
BTSect = Shell(PathCD + ".\btsect.exe /NT52 " + ParPath, vbHide)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, BTSect)
isDone = False
Do

Call GetExitCodeProcess(hProcess, ExitCode)
Debug.Print ExitCode
DoEvents
Loop While ExitCode = STILL_ALIVE
Call CloseHandle(hProcess)
isDone = True

title.Caption = "正在安装系统,这将需要几分钟时间,请稍候...."
CopySys = Shell(PathCD + ".\7z.exe x .\SOURCES\setup.exe -O" + ParPath + "\", vbHide)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, CopySys)
isDone = False
Do

Call GetExitCodeProcess(hProcess, ExitCode)
Debug.Print ExitCode
DoEvents
Loop While ExitCode = STILL_ALIVE
Call CloseHandle(hProcess)
isDone = True
cancel.Enabled = True

title.Caption = "系统文件复制完成,请重新启动计算机以完成安装!"
enter.Visible = False
complete.Visible = True

End If

End Sub

Private Sub complete_Click()
Unload Me
End Sub

Private Sub cancel_Click()
Unload Me
End Sub
搜索更多相关主题的帖子: 进度 ByVal Long Lib Function 
2008-07-18 17:06
yandatou
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-7-20
收藏
得分:0 
有点长
有点长啊。可以简化些
2008-07-20 22:14
wyfandy
Rank: 1
来 自:深圳
等 级:新手上路
帖 子:376
专家分:0
注 册:2006-12-11
收藏
得分:0 
汗,你这代码也不整理一下,这样看会头痛呀

不论什么事,只要认准了一个目标,然后朝之不懈地努力,就一定实现。编程爱好者QQ群:21318556
2008-07-21 12:33
multiple19O2
Rank: 1
等 级:新手上路
帖 子:326
专家分:0
注 册:2007-8-29
收藏
得分:0 
除非你查内存,否则需要“外部程序”配合。
2008-07-21 12:47
shuyoufeng
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2008-7-3
收藏
得分:0 
就是要举个例子,比如说vb用shell运行外部程序,怎么显示外部程序的执行进度,比如用一个进度条或动态显示一个百分比的数字等等,谢谢!
2008-07-28 10:59
octillion
Rank: 1
等 级:新手上路
帖 子:195
专家分:0
注 册:2008-7-24
收藏
得分:0 
让外部程序有一点进度就Post信息到你的程序里,Post的方式可以用网络连接或者DDE或者SendMessage之类
2008-07-28 11:47
快速回复:vb 进度条问题请教?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019123 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved