Is there a way to make a panel of the status bar control act like a progress bar? I see examples of this in many apps, including IE right now during transitions from page to page on this site. Thanks for your help.
Printable View
Is there a way to make a panel of the status bar control act like a progress bar? I see examples of this in many apps, including IE right now during transitions from page to page on this site. Thanks for your help.
It's easier just to add a Statusbar panel, and overlay a standard progress bar on top of it.
If you're feeling really clever you could even dynamically adjust the size of the progress bar to fit the panel at runtime. The end user would be none the wiser.
I'm not aware of any way you can create a progress bar WITHIN a StatusBar. But like you said - Explorer does it so it must be possible.
You might have to dive into the realms of WinAPI to achieve what you want...
:D
Code: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 msg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const WM_USER As Long = &H400
Private Const SB_GETRECT As Long = (WM_USER + 10)
Public Sub ShowProgressInStatus(pProgress As ProgressBar, pStatus As StatusBar, pPanelIndex As Integer)
Dim tRC As RECT
pProgress.Appearance = ccFlat
'Get the size of the given panel
SendMessage pStatus.hwnd, SB_GETRECT, pPanelIndex, tRC
'Convert to Twips
With tRC
.Top = (.Top * Screen.TwipsPerPixelY) + 30
.Left = (.Left * Screen.TwipsPerPixelX) + 30
.Bottom = (.Bottom * Screen.TwipsPerPixelY) - .Top - 30
.Right = (.Right * Screen.TwipsPerPixelX) - .Left - 30
End With
'Reparent the ProgressBar to the statusbar
With pProgress
SetParent .hwnd, pStatus.hwnd
.Move tRC.Left, tRC.Top, tRC.Right, tRC.Bottom
.Visible = True
.Value = 0
End With
End Sub
Private Sub Command1_Click()
ShowProgressInStatus ProgressBar1, StatusBar1, 0
ProgressBar1.Value = 50
End Sub
WOW! Thanks a lot, Frans! I tried it and it works great!!