VB and VBA Users Source Code: Changing the background/foreground colour of a progress bar
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Changing the background/foreground colour of a progress bar
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, February 25, 2002
Hits:
1025
Category:
Windows API
Article:
The following code demonstrates how to change the background/foreground colour of a progress bar. 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 'Purpose : Sets the background/foreground colour of a progress bar. 'Inputs : lProgressBarHwnd The handle to the progress bar ' lColour The colour to change the progress bar to. ' bForeground If True sets the foreground colour, else sets the background colour. 'Outputs : N/A 'Author : Andrew Baker (copyright www.vbusers.com) 'Date : 31/Jan/2002 'Notes : Requires a reference to "Microsoft Windows Common Controls" 'Revisions : Sub ProgressSetColor(lProgressBarHwnd As Long, lColour As Long, bForeground As Boolean) Const WM_USER = &H400, CCM_FIRST As Long = &H2000& Const CCM_SETBKCOLOR As Long = (CCM_FIRST + 1), PBM_SETBKCOLOR As Long = CCM_SETBKCOLOR Const PBM_SETBARCOLOR As Long = (WM_USER + 9) On Error GoTo ErrFailed If bForeground Then Call SendMessage(lProgressBarHwnd, PBM_SETBARCOLOR, 0&, ByVal lColour) Else Call SendMessage(lProgressBarHwnd, PBM_SETBKCOLOR, 0&, ByVal lColour) End If Exit Sub ErrFailed: Debug.Print "Error in ProgressSetColor: " & Err.Description Debug.Assert False End Sub 'Demonstration code Private Sub Form_Load() ProgressBar1.Value = 50 ProgressSetColor ProgressBar1.hwnd, RGB(255, 0, 0), True ProgressSetColor ProgressBar1.hwnd, RGB(0, 255, 0), False End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder