Private Declare Function SetParent Lib "user32" _
(ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As Long
'used to change progressbar colour
Private Const WM_USER = &H400
Private Const CCM_FIRST As Long = &H2000&
Private Const CCM_SETBKCOLOR As Long = (CCM_FIRST + 1)
'set progressbar backcolor in IE3 or later
Private Const PBM_SETBKCOLOR As Long = CCM_SETBKCOLOR
'set progressbar barcolor in IE4 or later
Private Const PBM_SETBARCOLOR As Long = (WM_USER + 9)
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 Sub Form_Load()
Dim pnl As Panel
Dim btn As Button
Dim x As Long
'create statusbar
With StatusBar1
For x = 1 To 3
Set pnl = .Panels.Add(, , "", sbrText)
pnl.Alignment = sbrLeft
pnl.Width = 1800
pnl.Bevel = sbrInset
If x = 3 Then pnl.AutoSize = sbrSpring
If x = 1 Then pnl.Text = "Status/Progbar Demo"
Next
End With
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
SetParent
The SetParent function changes the parent window of the specified child window.
HWND SetParent(
HWND hWndChild, // handle to window
HWND hWndNewParent // new parent window
);
Parameters
hWndChild
[in] Handle to the child window.
hWndNewParent
[in] Handle to the new parent window. If this parameter is NULL, the desktop window becomes the new parent window.
Windows 2000/XP: If this parameter is HWND_MESSAGE, the child window becomes a message-only window.
Return Values
If the function succeeds, the return value is a handle to the previous parent window.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.