Now, I'm trying to change the bar color and background color of a progress bar in VB.
The way to do this is to send the PBM_SETBARCOLOR and PBM_SETBKCOLOR to the progress bar.
I coded :
Code:
Option Explicit
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 Const WM_USER = &H400
Private Const PBM_SETBARCOLOR = (WM_USER + 9)
Private Const CCM_FIRST = &H2000
Private Const CCM_SETBKCOLOR = (CCM_FIRST + 1)
Private Const PBM_SETBKCOLOR = CCM_SETBKCOLOR
//command button......when clicked, fill progress bar
Private Sub cmdGo_Click()
Dim i As Integer
For i = 0 To 100
ProgressBar1.Value = i
Next i
End Sub
Private Sub Form_Load()
'suppose to be black for progress bar's backgound
SendMessage ProgressBar1.hwnd, PBM_SETBKCOLOR, _
0, RGB(0, 0, 0)
'suppose to be yellow for progress bar's bar
'color
SendMessage ProgressBar1.hwnd, PBM_SETBARCOLOR, _
0, RGB(255, 255, 0)
End Sub
But for some reasons, the color of both the bar and background of the progress bar always seems to be bright yellowish-green, despite the many different colors I set! Why?
Does anyone have any idea? I've attached the project to this thread.
Please and thanks a lot!
"Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria
"I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria
Option Explicit
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 cmdBackColor_Click()
' Change background color
On Error GoTo errHandler
With CommonDlg
.CancelError = True
'Show common dialog box
.ShowColor
' Change to selected background color
SendMessage ProgressBar1.hwnd, 8193, 0, ByVal .Color
End With
Exit Sub
errHandler:
End Sub
Private Sub cmdForeColor_Click()
' Change foreground color
On Error GoTo errHandler
With CommonDlg
.CancelError = True
'Show common dialog box
.ShowColor
' Change to selected foreground color
SendMessage ProgressBar1.hwnd, 1033, 0, ByVal .Color
End With
Exit Sub
errHandler:
End Sub
Private Sub Timer1_Timer()
If ProgressBar1.Value >= ProgressBar1.Max Then ProgressBar1.Value = ProgressBar1.Min
ProgressBar1.Value = ProgressBar1.Value + 1
End Sub
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.