Private Declare Function SetParent Lib "user32" _
(ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As Long
Private Function AttachProgBar(pb As ProgressBar, _
sb As StatusBar, _
nPanel As Long, _
pading As Long)
If defProgBarHwnd = 0 Then
'change the parent
defProgBarHwnd = SetParent(pb.hwnd, sb.hwnd)
With sb
'adjust statusbar. Doing it this way
'relieves the necessity of calculating
'the statusbar position relative to the
'top of the form. It happens so fast
'the change is not seen.
.Align = vbAlignTop
.Visible = False
'change, move, set size and re-show
'the progress bar in the new parent
With pb
.Visible = False
.Align = vbAlignNone
.Appearance = ccFlat
.BorderStyle = ccNone
.Width = sb.Panels(nPanel).Width
.Move (sb.Panels(nPanel).Left + pading), _
(sb.Top + pading), _
(sb.Panels(nPanel).Width - (pading * 2)), _
(sb.Height - (pading))
.Visible = True
.ZOrder 0
End With
'restore the statusbar to the
'bottom of the form and show
.Panels(nPanel).AutoSize = sbrNoAutoSize
.Align = vbAlignBottom
.Visible = True
End With
End If
End Function
Private Sub Command1_Click()
Dim pading As Long
'parent the progress bar in the status bar
pading = 40
AttachProgBar ProgressBar1, StatusBar1, 2, pading
End Sub