[MFC] CProgressCtrl-在启用主题的情况下更改进度栏颜色 [英] [MFC] CProgressCtrl - Change progress bar color with themes enabled
本文介绍了[MFC] CProgressCtrl-在启用主题的情况下更改进度栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我想更改CProgressCtrl的条形颜色
我已经做到了,它可以在经典"主题环境下工作.但是,启用主题后,栏将诉诸主题指示的颜色.
有没有办法覆盖这个?我仍然希望以对话框为主题...
感谢您的阅读!
Pabs
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
推荐答案
好,我现在明白了.
我创建了自己的派生自CProgressCtrl的类,并覆盖了OnPaint命令.
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);
}
这篇关于[MFC] CProgressCtrl-在启用主题的情况下更改进度栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文