Hi there
Is it possible to have a progressbar on the status bar e.g Internet Explorer.
Thanks in advance ;p
Mark
Printable View
Hi there
Is it possible to have a progressbar on the status bar e.g Internet Explorer.
Thanks in advance ;p
Mark
Try this:
Code:'Author: Chris Eastwood
'Author's email: [email protected]
'Date Submitted: 2/22/1999
'Compatibility: VB 5
'Task: How to place a Progress Bar in A Status Bar Panel (VB5) - should
work with VB4(32 bit) and VB6.
'Declarations
'
' Module Declares for the StatProgressBar example
'
' Chris Eastwood Feb. 1999
'
' http://www.codeguru.com/vb
'
'
' API Declarations
'
Public 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 Long
'
' API Types
'
' RECT is used to get the size of the panel we're inserting into
'
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
'
' API Messages
'
Public Const WM_USER As Long = &H400
Public Const SB_GETRECT As Long = (WM_USER + 10)
'Code:
Private Sub ShowProgressInStatusBar(ByVal bShowProgressBar As Boolean)
Dim tRC As RECT
If bShowProgressBar Then
'
' Get the size of the Panel (2) Rectangle from the status bar
' remember that Indexes in the API are always 0 based (well,
' nearly always) - therefore Panel(2) = Panel(1) to the api
'
'
SendMessageAny StatusBar1.hwnd, SB_GETRECT, 1, tRC
'
' and convert it to twips....
'
With tRC
.Top = (.Top * Screen.TwipsPerPixelY)
.Left = (.Left * Screen.TwipsPerPixelX)
.Bottom = (.Bottom * Screen.TwipsPerPixelY) - .Top
.Right = (.Right * Screen.TwipsPerPixelX) - .Left
End With
'
' Now Reparent the ProgressBar to the statusbar
'
With ProgressBar1
SetParent .hwnd, StatusBar1.hwnd
.Move tRC.Left, tRC.Top, tRC.Right, tRC.Bottom
.Visible = True
.Value = 0
End With
Else
'
' Reparent the progress bar back to the form and hide it
'
SetParent ProgressBar1.hwnd, Me.hwnd
ProgressBar1.Visible = False
End If
End Sub
I believe God just spoke to me!! :)
Thanks
I found an API that would "paint" the Menu bar... can I transform this to paint the entire stausbar also?
Here's the menu color code:VB Code:
'****************************************************************************** 'Required API call declarations '****************************************************************************** 'CreateBrushIndirect is used to create the background brush for the menus Private Declare Function CreateBrushIndirect Lib "gdi32" (lpLogBrush As LOGBRUSH) As Long 'GetMenu is used to get the handle to the menus Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long 'GetMenuInfo is used to get the current info for the menu (so we don't change anything we shouldn't by mistake) Private Declare Function GetMenuInfo Lib "user32" (ByVal hMenu As Long, lpcmi As tagMENUINFO) As Long 'SetMenuInfo is used to set the background brush back to the menu and all sub-menus Private Declare Function SetMenuInfo Lib "user32" (ByVal hMenu As Long, lpcmi As tagMENUINFO) As Long '****************************************************************************** 'Required API Type Definitions '****************************************************************************** 'Used in the Calls to CreateBrushIndirect Private Type LOGBRUSH lbStyle As Long 'Style type (we only need to create a solid background for this example) lbColor As Long 'Set the color of the brush lbHatch As Long 'Hatch style (not used in this example because it's ignored for Solid style) End Type 'Used in GetMenuInfo and SetMenuInfo calls Private Type tagMENUINFO cbSize As Long 'The size of the type structure (use len to calculate) fMask As Long 'Mask of information/Actions to process dwStyle As Long 'Menu Style (not used in this example) cyMax As Long 'Maximum height of menu in pixels (not used in this example) hbrBack As Long 'Handle to background brush dwContextHelpID As Long 'Help Context ID (not used in this example) dwMenuData As Long 'Menu Data (again not used in this example) End Type '****************************************************************************** 'API Constant declarations '****************************************************************************** Private Const BS_SOLID = 0 'Solid style for brush Private Const MIM_APPLYTOSUBMENUS = &H80000000 'Apply to Sub-Menus Mask Private Const MIM_BACKGROUND = &H2 'Background Mask Public Sub PaintTheMenu() Dim ret As Long 'Variable to hold return values from GetMenuInfo and SetMenuInfo Dim hMenu As Long 'Variable to hold the handle to the menu Dim hBrush As Long 'Variable to hold the handle to the background brush we are going to create Dim lbBrushInfo As LOGBRUSH 'Variable to hold the information to pass to the CreateBrushIndirect API Dim miMenuInfo As tagMENUINFO 'Variable to hold the menu info lbBrushInfo.lbStyle = BS_SOLID 'Set our brush type to solid lbBrushInfo.lbColor = vbRed 'Here we set our brush color lbBrushInfo.lbHatch = 0 'This value is ignored I set it to 0 to make sure nothing weird will happen hBrush = CreateBrushIndirect(lbBrushInfo) 'We create our brush hMenu = GetMenu(main.hwnd) 'Get the handle to the menu that we are modifying (note we pass the form's hWnd because it is the owner of the menu) miMenuInfo.cbSize = Len(miMenuInfo) 'Set the MenuInfo structure size so that we don't get errors ret = GetMenuInfo(hMenu, miMenuInfo) 'Go and get the actual menu info should return non-zero if successful miMenuInfo.fMask = MIM_APPLYTOSUBMENUS Or MIM_BACKGROUND 'Set the mask for the changes (changing the background for menu and all sub-menus) miMenuInfo.hbrBack = hBrush 'Assign our brush to the menu info ret = SetMenuInfo(hMenu, miMenuInfo) 'Write our info back to the menu and we're done. (should return non-zero if successful) End Sub
Also... will this code work safely on Me, 2000 and XP?
davem -
How would you use this code? Do you just call PaintTheMenu in the Form Load Event?
Yeah bloodeye.
THere is a problem though... if you have hidden menu's (for popups) then those don't get painted... anyone, ideas?
Try setting the menus visible at startup, call the PaintMenu code, and then set their visible property to false again.
Maybe that'll work.
Tried that... apparently when you set them back to visible = false they loose their color. I'm gonna see what I can come up with but I'm not strong in API.
Any idea on the painting the statusbar ei?
Well, there's lots of 3rd party controls that can do that.
Or, you can just have 1 picture box, and another picturebox inside the first one that acts like a progress bar.
I remember seeing some code at PSC for changing the backcolor and forecolor of a statusbar....
No... I don't need the progress bar... my question is even simpler. I just need to make the statusbar (the entire thing - not just specific panels) another color.