请问各位前辈,怎样才能在StatusBar中显示程序执行进度?就像IE中那样 谢谢
还要有一个progressbar
用api函数setparent把它放进StatusBar里面。
需要一个Form\Timer\CommandButton\ProgressBar\StatusBar
Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_USER = &H400
Private Const SB_GETRECT = (WM_USER + 10)
Private Type RECT
Left As Long
As Long
Right As Long
Bottom As Long
End Type
Private Sub Command1_Click()
ShowProgressInStatusBar True
Timer1.Enabled = True
End Sub
Private Sub ShowProgressInStatusBar(ByVal bShowProgressBar As Boolean)
Dim tRC As RECT
If bShowProgressBar Then
SendMessage StatusBar1.hwnd, SB_GETRECT, 1, tRC
With tRC
. = (. * Screen.TwipsPerPixelY) - 5
.Left = (.Left * Screen.TwipsPerPixelX)
.Bottom = (.Bottom * Screen.TwipsPerPixelY) - . - 10
.Right = (.Right * Screen.TwipsPerPixelX) - .Left
End With
With ProgressBar1
SetParent .hwnd, StatusBar1.hwnd
.Move tRC.Left, tRC., tRC.Right, tRC.Bottom
.Visible = True
.Value = 1
End With
Else
SetParent ProgressBar1.hwnd, Me.hwnd
ProgressBar1.Visible = False
End If
End Sub
Private Sub Form_Load()
With Timer1
.Enabled = False
.Interval = 10
End With
End Sub
Private Sub Timer1_Timer()
If ProgressBar1.Value = 100 Then
Timer1.Enabled = False
ShowProgressInStatusBar False
Else
ProgressBar1.Value = ProgressBar1.Value + 1
End If
End Sub