I have a problem with changing the color of the progress bar. Initially I created an instance for that progress control and in the
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:
Progress bar colors
- 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.
- 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.
- 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.