把这个放到模块中: Option ExplicitPublic Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long Public Declare Function SendMessageAny Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Type RECT Left As Long Top As Long Right As Long Bottom As Long End TypeMessages ' Public Const WM_USER As Long = &H400 Public Const SB_GETRECT As Long = (WM_USER + 10)把这个放在form1中。 Option Explicit 'Private Sub Command1_Click() Command1.Enabled = False ProgressBar1.Min = 0 ProgressBar1.Max = 100 ShowProgressInStatusBar True Timer1.Enabled = True End SubPrivate Sub ShowProgressInStatusBar(ByVal bShowProgressBar As Boolean) Dim tRC As RECT
If bShowProgressBar Then SendMessageAny StatusBar1.hwnd, SB_GETRECT, 0, tRC With tRC .Top = (.Top * Screen.TwipsPerPixelY) .Left = (.Left * Screen.TwipsPerPixelX) .Bottom = (.Bottom * Screen.TwipsPerPixelY) - .Top .Right = (.Right * Screen.TwipsPerPixelX) - .Left End With With ProgressBar1 SetParent .hwnd, StatusBar1.hwnd .Move tRC.Left, tRC.Top, tRC.Right, tRC.Bottom .Visible = True .Value = 0 End With
Else SetParent ProgressBar1.hwnd, Me.hwnd ProgressBar1.Visible = False End If
End SubPrivate Sub Form_Unload(Cancel As Integer) ShowProgressInStatusBar False
End SubPrivate Sub Timer1_Timer() Static lCount As Long
lCount = lCount + 5
If lCount > 100 Then Timer1.Enabled = False ShowProgressInStatusBar False Command1.Enabled = True lCount = 0 End If
Option ExplicitPublic Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Declare Function SendMessageAny Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypeMessages
'
Public Const WM_USER As Long = &H400
Public Const SB_GETRECT As Long = (WM_USER + 10)把这个放在form1中。
Option Explicit
'Private Sub Command1_Click()
Command1.Enabled = False ProgressBar1.Min = 0
ProgressBar1.Max = 100 ShowProgressInStatusBar True Timer1.Enabled = True
End SubPrivate Sub ShowProgressInStatusBar(ByVal bShowProgressBar As Boolean) Dim tRC As RECT
If bShowProgressBar Then SendMessageAny StatusBar1.hwnd, SB_GETRECT, 0, tRC With tRC
.Top = (.Top * Screen.TwipsPerPixelY)
.Left = (.Left * Screen.TwipsPerPixelX)
.Bottom = (.Bottom * Screen.TwipsPerPixelY) - .Top
.Right = (.Right * Screen.TwipsPerPixelX) - .Left
End With With ProgressBar1
SetParent .hwnd, StatusBar1.hwnd
.Move tRC.Left, tRC.Top, tRC.Right, tRC.Bottom
.Visible = True
.Value = 0
End With
Else SetParent ProgressBar1.hwnd, Me.hwnd
ProgressBar1.Visible = False
End If
End SubPrivate Sub Form_Unload(Cancel As Integer) ShowProgressInStatusBar False
End SubPrivate Sub Timer1_Timer()
Static lCount As Long
lCount = lCount + 5
If lCount > 100 Then
Timer1.Enabled = False
ShowProgressInStatusBar False
Command1.Enabled = True
lCount = 0
End If
ProgressBar1.Value = lCount
End Sub