Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I am wanting to change the bar color of a CProgressCtrl

I have done this and it works on a "classic" theme environment. But when themes are enabled the bar resorts to the color dictated by the theme.

Is there a way to override this? I still want the dialog to be themed...

Thanks for reading!

Pabs
Posted

1 solution

Ok, I understand this now.

I created my own class derived from CProgressCtrl and override the OnPaint command.

void CMyProgress::OnPaint()
{
    CPaintDC dc(this); // device context for painting
    CRect clientRect ;
    CRect windowRect;

    GetWindowRect(windowRect);
    windowRect.SetRect(0, 0, windowRect.Width(), windowRect.Height());

    GetClientRect(clientRect);
    clientRect.SetRect(1, 1, windowRect.Width() + 1, windowRect.Height() + 1);

    // Draw the border of the progress control. Use a standard 3D border
    dc.Draw3dRect(windowRect, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DLIGHT));

    CRect barRect = clientRect;
    //Is Control Horizontal or Vertical.
    if(! GetStyle() && PBS_VERTICAL)
    {
        int rangeLow, rangeHigh;
        GetRange(rangeLow, rangeHigh);

        int x = GetPos(), y;

        if(x < rangeLow || x > rangeHigh)
        return;

        // Calculate the width

        x -= rangeLow;
        x *= 100;
        x /= (rangeHigh - rangeLow);

        y = clientRect.Width();
        y *= x;
        y /= 100;
        y += clientRect.left;

        // Using the y variable as the new width, define a new rectangle

        barRect.right = barRect.left + y;
    }
    else
    {
        int rangeLow, rangeHigh;
        GetRange(rangeLow, rangeHigh);

        int y = GetPos(), x;

        if(y < rangeLow || y > rangeHigh)
        return;

        //Calculate Height
        y -= rangeLow;
        y *= 100;
        y /= (rangeHigh - rangeLow);

        x = clientRect.Height();
        x *= y;
        x /= 100;
        x += clientRect.top;

        
        barRect.top = barRect.bottom - x;

    }
    // Use barRect as the rectangle for drawing the progress bar.
    CBrush brush;
    brush.CreateSolidBrush(m_BarColour);
    dc.FillRect(barRect, &brush);

}
 
Share this answer
 
v2

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