Shaul
Shaul

Reputation: 469

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?

Upvotes: 4

Views: 2213

Answers (3)

Drakorcarnis
Drakorcarnis

Reputation: 21

I've had the exact same problem but didn't manage to enable the borders. However by changing the background of the bars it looks okay:

SendMessage(hwndPBAR, PBM_SETBKCOLOR, 0, 0x00DCDCDC); //grey

Upvotes: 0

GobeRadJem32
GobeRadJem32

Reputation: 102

Change style of progress bar with write this manifest:

 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" 
manifestVersion="1.0">
 <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
  <security>
       <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" 
   uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="Win32" 
    name="Microsoft.Windows.Common-Controls" 
    version="6.0.0.0"
                    processorArchitecture="*" 
     publicKeyToken="6595b64144ccf1df" language="*"/>
     </dependentAssembly>
    </dependency>

and this resource:

1 24"manifestname.manifest"

Upvotes: 0

Remy Lebeau
Remy Lebeau

Reputation: 595320

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.

Upvotes: 3

Related Questions