I have a problem with changing the color of the progress bar. Initially I created an instance for that progress control and in the OnInitDialog()
. I am trying change the color of the progress bar (initially the progress bar color is green). Now, I tried setting the bar color to red using this piece of code in the OnInitDialog()
as follows,
BOOL OnInitDialog()
{
CPropertyPage::OnInitDialog();
m_ProgressBar->SetRange32(0,100);
m_ProgressBar->SetPos(50);
m_ProgressBar->SetBarColor(RGB(255,0,0));
return TRUE;
}
This is the thing I had to change the bar color, and I am using Windows 7 OS. One thing what I observed is when I changed the theme to "windows classic" then I am able to see the color I have set (in this case red). But again if I get back to the Windows 7 aero theme the color is green again.
Moreover I even checked the SetBkColor
method here and it has the same issue that I faced when I used SetBarColor()
.
Can anyone suggest a possible way to change the bar color in all themes (I think that would be fine if it supported all kinds of themes)?
The progress bar color is determined by the current system theme; there is no provided customization capability. If the user has the "Windows Classic" theme set, the progress bar fills with the system highlight color. If the user has the Aero theme set, then the Aero progress bar styles are used, which does indeed with green.
If you want to change how progress bars are rendered, you will need to change the system-wide theme. Of course, this is not something an application should do—it is something that the user would do because they prefer a different theme. For example, they might install a theme that has blue progress bars. There are plenty of examples online. It is easy to generate these themes; you simply open the
aero.msstyle
file in a resource editor and modify the images it uses to display progress bars.However, the Aero-style progress bar does have three different states: normal, paused, and error. In the normal state, it is filled with green. In the paused state, it is filled with yellow, and in the error state, it is filled with red.
But you shouldn't change the state of the progress bar just because you want it to be a certain color—the three states have specific semantic meanings aside from their colors. In theory, the colors could even be changed to fit different locales (although I doubt they are). Consider what the Windows User Experience Guidelines have to say on progress bars; specifically:
If you've decided that changing the state of the progress bar is appropriate for your situation, you can do it by sending the the
PBM_SETSTATE
message to the control window:Of course, it only works when the Aero theme is enabled. Nothing will happen to the "Classic"-style progress bars.
You can disable visual styles for your progress bar (and any other control):
and you will be able to change colors, margins, etc. as you need
After creating MFC Project ---
1] Take progress bar from toolbox to Dialog pane ....
2] Now Add an Variable for Progress bar by
CODE :
INSIDE ::OnInitDialog() method ->>
INSIDE UserDefined Function ->> int r = 50 ; int g = 50 ; int b = 250 ;
Enjoy Coding .......!!!
Enjoy MFC .....!!