CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Progress Bar Colors



On Thu, 17 Sep 1998 ps_se@lonelyplanet.com.au wrote:

> Does anyone know of a way to change the color of the TprogressBar 
> component from its default system color (usually blue)?


Well I thought this was going to be an easy question, but instead I've 
spent most of the afternoon frustrated with it <G>.

The background color of the progress bar can be changed quite easily.  
Instructions for ths are located in the help for the TProgressBar Brush 
property and involve changing the Brush->Color.  I changed this color in 
my forms OnShow event so it would display correctly before it was used.

Changing the foreground color turned out to be (for me anyway) 
impossible, but I'll point you in the direction I went and you can try it 
for yourself.  Maybe you'll have better luck than I did.

Since the help for TProgressBar says that the bar is filled in using the 
system highlight color, it seemed like it would be a very simple matter 
of changing the system highlight color, using the progress bar, then 
changing back to the system defaults.  This turned out not to be the case.

I changed every system color defined in winuser.h (and then some <g>) and 
never found a color designation which when changed would yield the 
desired effect.  The two functions used for modifying the system colors 
are GetSysColor and SetSysColors.  I've included a snippet of code 
below.  If you do find a solution for this I'd be interested to hear it!

Daniel Hallmark

CODE notes:  
This is sloppy code and lotta better ways to even run this test, just 
threw this together real quick.  I put a single button and progressbar on 
a form.  The progess bar has min of 0 and max of 10000 with a step of 1.

--in unit1.hpp
   int systemColor;         // select which system color to change
   DWORD currentSysColor;   // store color so you can put it back
   int colorArray[1];       // req'd for SetSysColors - sys color to change
   COLORREF color[1];       // req'd for SetSysColors - RBG color to use

--FormCreate
   systemColor=4;  // substitute values from winuser.h -- 4 = COLOR_MENU

   currentSysColor = GetSysColor(systemColor);  // save current color
   colorArray[0]=systemColor;     // this is what you will be changing
   color[0] = 0x0000FFFF;         // this is the color you will change it to

   SetSysColors(1,colorArray,color);  // make the change

--FormDestroy
   color[0]=currentSysColor;          // put original color in array
   SetSysColors(1,colorArray,color);  // restore original system colors

--Button1Click
   for(int i=1; i<10000; ++i)
      ProgressBar1->StepIt();




W Komornicki's Home Page | Main Index | Thread Index