Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Progress bars with color and borders with common controls

I had colorful progress bars in my GUI that I liked:

Original

However, I wanted the GUI to look be in the Windows 7 style when on Windows 7, so I added this pragma

#pragma comment( linker, "/manifestdependency:\"type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \
language='*'\"")

But this resulted in monochrome (green), animated glowing toolbars that I don't like:

glowing

So I removed the styles by entering:

  SetWindowTheme(hProgress, L" ", L" ");

The results where not bad:

Borderless

However, note that there's no border around the progress bar though I rely on the same resource file. How do I set the progress bar to the original look while retaining the Windows 7 look for the rest of the window?

like image 763
Shaul Avatar asked Sep 03 '25 15:09

Shaul


1 Answers

When Visual Styles are enabled, a standard Win32 ProgressBar does not support custom coloring, it gets its coloring from the current theme instead. That is why your ProgressBars all turned green. However, you can use the PBM_SETSTATE message to set the ProgressBar's state to PBST_NORMAL (green), PBST_ERROR (red), or PBST_PAUSED (yellow).

Beyond that, to display a themed ProgressBar with custom colors, you have to owner-draw a custom control using DrawThemeBackground() directly, drawing the various components of the "PROGRESS" class as needed. The standard red, green, cyan, and yellow colors can be drawn by setting the iStateId parameter to PBFS_ERROR, PBFS_NORMAL, PBFS_PARTIAL, or PBFS_PAUSED (respectively) when drawing the PP_FILL portion (the colored bar showing the current progress). If you need any other colors, though, it gets a bit trickier. The following article shows an example of drawing a standard themed ProgressBar with a gradient color blend:

Gradient Bar Control

The technique demonstrated draws a standard ProgressBar first using the PBFS_NORMAL (green) state, then uses HSL saturation and intensity transformations to alter the color values of the PP_FILL pixels to make them into the desired colors.

like image 86
Remy Lebeau Avatar answered Sep 05 '25 16:09

Remy Lebeau