MyProgressCtrl

// MyProgressCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "iDART_UI.h"
#include "MyProgressCtrl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


IMPLEMENT_DYNAMIC(MyProgressCtrl, CProgressCtrl)

MyProgressCtrl::MyProgressCtrl()
{
 m_clrBk=RGB(0,0,0);
 m_clrText=RGB(255,255,255);
 m_clrStart=RGB(255,0,0);
 m_clrEnd=RGB(0,0,255);
 m_nLower=0;
 m_nUpper=100;
 m_nCurrentPos=0;
 m_nStep=100;
 m_bShowPercent=TRUE;
}

MyProgressCtrl::~MyProgressCtrl()
{
}


BEGIN_MESSAGE_MAP(MyProgressCtrl, CProgressCtrl)
 ON_WM_PAINT()
END_MESSAGE_MAP()

 

// MyProgressCtrl message handlers


void MyProgressCtrl::OnPaint()
{
 CPaintDC dc(this); // device context for painting

 // TODO: Add your message handler code here
 float tag=(float)m_nCurrentPos/(float)m_nUpper;

 float r,g,b;
 r=(float)GetRValue(m_clrStart);
 g=(float)GetGValue(m_clrStart);
 b=(float)GetBValue(m_clrStart);

 float dr,dg,db;
 dr=(float)(GetRValue(m_clrEnd)-GetRValue(m_clrStart))/(float)m_nStep*tag;
 dg=(float)(GetGValue(m_clrEnd)-GetGValue(m_clrStart))/(float)m_nStep*tag;
 db=(float)(GetBValue(m_clrEnd)-GetBValue(m_clrStart))/(float)m_nStep*tag;

 CRect rectClient;
 GetClientRect(&rectClient);
 float nLen=(float)rectClient.right*tag/(float)m_nStep;

 CRect rectFill;
 CBrush brush;

 for (int i=0;i<m_nStep;i++)
 {
  r+=dr;
  g+=dg;
  b+=db;
  ::SetRect(&rectFill,(int)(nLen*i),0,(int)(nLen*(i+1)),rectClient.bottom);
  VERIFY(brush.CreateSolidBrush(RGB(r,g,b)));
  dc.FillRect(&rectFill,&brush);
  VERIFY(brush.DeleteObject());
 }
 if (m_bShowPercent)
 {
  dc.SetTextColor(m_clrText);
  dc.SetBkColor(m_clrBk);
  //dc.SetBkMode(TRANSPARENT);
  CString str;
   str.Format("%0.1f%%",100*tag);
  dc.DrawText(str,&rectClient,DT_VCENTER|DT_CENTER|DT_SINGLELINE);
 }

 // Do not call CProgressCtrl::OnPaint() for painting messages
}


void MyProgressCtrl::SetRange(short nLower, short nUpper)
{
 m_nLower=nLower;
 m_nUpper=nUpper;
 CProgressCtrl::SetRange(nLower,nUpper);
}

int MyProgressCtrl::SetPos(int nPos)
{
 m_nCurrentPos=nPos;
 return CProgressCtrl::SetPos(nPos);
}

int MyProgressCtrl::SetStep(int nStep)
{
 m_nStep=nStep;
 return CProgressCtrl::SetStep(nStep);
}

void MyProgressCtrl::SetBkColor(COLORREF color)
{
 m_clrBk=color;
}

void MyProgressCtrl::SetTextColor(COLORREF color)
{
 m_clrText=color;
}

void MyProgressCtrl::SetStartColor(COLORREF color)
{
 m_clrStart=color;
}

void MyProgressCtrl::SetEndColor(COLORREF color)
{
 m_clrEnd=color;
}


COLORREF MyProgressCtrl::GetBkColor()
{
 return m_clrBk;
}

COLORREF MyProgressCtrl::GetTextColor()
{
 return m_clrText;
}

COLORREF MyProgressCtrl::GetStartColor()
{
 return m_clrStart;
}

COLORREF MyProgressCtrl::GetEndColor()
{
 return m_clrEnd;
}


void MyProgressCtrl::SetShowPercent(BOOL flag)
{
 m_bShowPercent=flag;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云雨巫山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值