现在的位置: 首页 > 综合 > 正文

MyProgressCtrl

2013年09月04日 ⁄ 综合 ⁄ 共 2590字 ⁄ 字号 评论关闭

// 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;
}

抱歉!评论已关闭.