• 大小: 146KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-12
  • 语言: C/C++
  • 标签: MFC  进度条  

资源简介

非常漂亮的MFC进度条程序,并且封装成了类,可直接调用

资源截图

代码片段和文件信息

// GradientProgressCtrl.cpp : implementation file
#include “stdafx.h“
#include “GradientProgressCtrl.h“

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

/////////////////////////////////////////////////////////////////////////////
// CGradientProgressCtrl

CGradientProgressCtrl::CGradientProgressCtrl()
{
//初始化
m_nLower = 0;
m_nUpper = 100;
m_nCurrentPosition = 0;
m_nStep = 10;

//m_clrStart = COLORREF(RGB(247 12834));
//m_clrEnd =  COLORREF(RGB(4523586));
//m_clrBkGround = ::GetSysColor(COLOR_3DFACE);
//m_clrText = COLORREF(RGB(95 60 119));
// 
m_clrStart = COLORREF(RGB(219 253255));
m_clrEnd =  COLORREF(RGB(00205));
m_clrBkGround = ::GetSysColor(COLOR_3DFACE);
m_clrText = COLORREF(RGB(95 60 119));

m_bShowPercent = FALSE;
}

CGradientProgressCtrl::~CGradientProgressCtrl()
{
}


BEGIN_MESSAGE_MAP(CGradientProgressCtrl CProgressCtrl)
//{{AFX_MSG_MAP(CGradientProgressCtrl)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGradientProgressCtrl message handlers

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

//如果进度条的当前位置不正确,则渐变到背景色
if (m_nCurrentPosition <= m_nLower || m_nCurrentPosition >= m_nUpper)
{
CRect rect;
GetClientRect(rect);
CBrush brush;
brush.CreateSolidBrush(::GetSysColor(COLOR_3DFACE));
dc.FillRect(&rect &brush);
VERIFY(brush.Deleteobject());
return;
}


//获得需要渐变的区域
CRect rectClient;
GetClientRect(&rectClient);
float maxWidth((float)m_nCurrentPosition/(float)m_nUpper * (float)rectClient.right);


//画渐变颜色
DrawGradient(&dc rectClient (int)maxWidth);

//如果需要显示百分数,则显示
if (m_bShowPercent)
{
CString percent;
percent.Format(_T(“%.0f%%“) 100.0f*(float)m_nCurrentPosition/(float)m_nUpper);
dc.SetTextColor(m_clrText);
dc.SetBkMode(TRANSPARENT);
dc.DrawText(percent &rectClient DT_VCENTER |  DT_CENTER | DT_SINGLELINE);
}
}


//设置进度条范围
void CGradientProgressCtrl:: SetRange(int nLower int nUpper)
{
m_nLower = nLower;
m_nUpper = nUpper;
m_nCurrentPosition = nLower;
CProgressCtrl::SetRange(nLower nUpper);
}

//设置进度条的位置
int CGradientProgressCtrl:: SetPos(int nPos)
{
m_nCurrentPosition = nPos;
return (CProgressCtrl::SetPos(nPos));
}

//设置进度条的步长
int CGradientProgressCtrl:: SetStep(int nStep)
{
m_nStep = nStep;
return (CProgressCtrl::SetStep(nStep));
}

int CGradientProgressCtrl:: StepIt(void)
{
m_nCurrentPosition += m_nStep;
return (CProgressCtrl::StepIt());
}

//在适当区域画渐变颜色
void CGradientProgressCtrl::DrawGradient(CPaintDC *pDC const RECT &rectClient const int &nMaxWidth)
{
RECT rectFill;    
float fStep;              
CBrush brush;


CProgressMemDC memDC(pDC);

//找到其实颜色和结束颜色之间的最大颜色值,决定渐变步长等
int r g b;
float rStep gStep bStep

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-09-21 14:35  MFCApplication5\
     文件          88  2015-07-03 10:44  MFCApplication5\desktop.ini
     目录           0  2015-09-21 14:35  MFCApplication5\MFCApplication5\
     文件         912  2015-06-09 11:43  MFCApplication5\MFCApplication5.sln
     文件       32768  2015-06-09 17:31  MFCApplication5\MFCApplication5.v11.suo
     文件       32768  2015-09-21 14:34  MFCApplication5\MFCApplication5.v12.suo
     文件        4333  2015-06-09 16:50  MFCApplication5\MFCApplication5\GradientProgressCtrl.cpp
     文件        2210  2015-06-09 11:48  MFCApplication5\MFCApplication5\GradientProgressCtrl.h
     文件        1747  2015-06-09 13:25  MFCApplication5\MFCApplication5\MemDC.h
     文件      108832  2015-06-09 13:36  MFCApplication5\MFCApplication5\MFCApplication5.aps
     文件        2485  2015-06-09 11:43  MFCApplication5\MFCApplication5\MFCApplication5.cpp
     文件         496  2015-06-09 11:43  MFCApplication5\MFCApplication5\MFCApplication5.h
     文件       10694  2015-06-09 13:36  MFCApplication5\MFCApplication5\MFCApplication5.rc
     文件        6354  2015-09-21 14:34  MFCApplication5\MFCApplication5\MFCApplication5.vcxproj
     文件        2401  2015-06-09 11:49  MFCApplication5\MFCApplication5\MFCApplication5.vcxproj.filters
     文件         164  2015-06-09 11:57  MFCApplication5\MFCApplication5\MFCApplication5.vcxproj.user
     文件        4563  2015-06-09 13:57  MFCApplication5\MFCApplication5\MFCApplication5Dlg.cpp
     文件         837  2015-06-09 13:37  MFCApplication5\MFCApplication5\MFCApplication5Dlg.h
     文件        4188  2015-06-09 11:43  MFCApplication5\MFCApplication5\ReadMe.txt
     目录           0  2015-06-09 11:43  MFCApplication5\MFCApplication5\res\
     文件        1432  2015-06-09 13:34  MFCApplication5\MFCApplication5\resource.h
     文件       67777  2012-01-11 01:22  MFCApplication5\MFCApplication5\res\MFCApplication5.ico
     文件         686  2015-06-09 11:43  MFCApplication5\MFCApplication5\res\MFCApplication5.rc2
     文件         148  2015-06-09 11:43  MFCApplication5\MFCApplication5\stdafx.cpp
     文件        1578  2015-06-09 11:43  MFCApplication5\MFCApplication5\stdafx.h
     文件         234  2015-06-09 11:43  MFCApplication5\MFCApplication5\targetver.h

评论

共有 条评论