Click here to Skip to main content
15,559,491 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having problem in 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 in green color). Now,I tried setting the bar color to red using this piece of code in the OnInitDialog() as follows,

C++
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 windows7 OS .One thing what I observed is when I changed the theme to "windows classic" then I am able to see the color I had set (in this case red). But again if I get back to the windows7 aero theme then again green color is coming.

Moreover I even checked for SetBkColor method here also facing the same issue that I faced when I used SetBarColor().

Can anyone suggest me the possible way to change bar color in all types of theme (I think that would be fine if it support all kind of themes).
Posted
Updated 14-Aug-14 4:17am
v2

See the Remarks section at http://msdn.microsoft.com/en-us/library/bb398776.aspx[^]. It's always worth checking the documentation first.
 
Share this answer
 
Please have a look if this is worth.

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.

sample of Aero-style progress bars, each set to a different state
1)Green progress bar
2)Light Yellowish bar
3)Red Progress bar

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:

Progress bar colors

1)Use red or yellow progress bars only to indicate the progress status, not the final results of a task. A red or yellow progress bar indicates that users need to take some action to complete the task. If the condition isn't recoverable, leave the progress bar green and display an error message.

2)Turn the progress bar red when there is a user recoverable condition that prevents making further progress. Display a message to explain the problem and recommend a solution.
3)Turn the progress bar yellow to indicate either that the user has paused the task or that there is a condition that is impeding progress but progress is still taking place (as, for example, with poor network connectivity). If the user has paused, change the Pause button label to Resume. If progress is impeded, display a message to explain the problem and recommend a solution.

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:

SendMessage(hwndProgressBar, PBM_SETSTATE, PBST_ERROR, 0);

Of course, it only works when the Aero theme is enabled. Nothing will happen to the "Classic"-style progress bars.

Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900